简体   繁体   中英

void method in Java Integration Tests

I have some experience with Unit Tests in Java and now started to write Integration Tests. However, I have some troubles understanding the Integration Test and writing test. Here are some issues that I would like to be clarified:

1. In my Java (based on Spring Boot) project, should I write Integration Test for Controllers or may it be also ok to write Integration Test for Services also (because there are some methods that are not called from Controller).

2. How can I test a void in service by Integration Test? I have not found a proper example on the web and I thought there is no need or way to test void via Integration Test. Any clarification pls?

OK, so here are the best practices in the area.

should I write Integration Test for Controllers or may it be also ok to write Integration Test for Services also

Most of the integration tests run for services. This is because each service can support several controllers and multiple interfaces in general. For controllers you do just the happy path tests on an integration level.

Any tests for controller specific exceptions go into the controller unit test, where you mock out the service.

How can I test a void in service by Integration Test?

You check its side effect. For example, you use a repository class to see if the relevant data has been persisted to the database.

Does this solve your problem? Let me know in the comments.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM