blibli-future / detroit

Project Detroit
5 stars 0 forks source link

Regarding authorization when unit testing #32

Open adhikasp opened 7 years ago

adhikasp commented 7 years ago

Controller Test

Just disable security entirely. Add @ActiveProfiles(value = "test")

Service Test

Mock authorization if and only if the uut (unit under test) require it. For example viewAllReview will return all review in database if user is a SuperAdmin or return only their review if Admin.

Mocking authorization could be done by setting SecurityContextHolder. Basically just call TestHelper.loginAs* (https://github.com/blibli-future/detroit/pull/31/commits/faaae5dfe22790f6bb150561773e8c9f40fe959e#diff-625d61011256f54c390262cecb67cdfd)