I have an integration test that tests a controller. I pass in a request and get a response back and the test passes. I however, before making the request, have to make a request to the /authenticate
endpoint to retrieve a token so I can put it in the header of the request. I have 2 questions
/add
, /get
etc. This unfortunately actually modifies the database (expected). Is there any way to run these tests but not actually modify the database? 1) In your Unit test class, Use @TestPropertySource(properties = {"security.basic.enabled=false"})
to override your security setting or @TestPropertySource(locations="classpath:test.properties")
if you want to use a totally different properties file testing.
2) You could use mocks, or if you don't want to use mocks in your integration tests, then you will have to clean the database after each test using something like this:
@After
public void tearDown() {
cleanupDatabase();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.