[JAVA] JUnit story
JUnit story
A crisp memorandum memo
mockito
powerMockito
JMockit
whitebox
DbSetup is easy to create DB test data in Java DbSetup
Start PowerMock and SpringJUnit4ClassRunner at the same time
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
Samples for each pattern of mockito and powerMock
https://qiita.com/euledge/items/a224777c15ae7145114a
How to test a private method in Java and partially mock that method
- When private is involved in the test https://qiita.com/shotana/items/142bcd03ef6f9f25bf2a
Injection using Spring runner makes it heavier (preferably it can be tested without injection).
- It may be better to use Injection Mocks and DI with a mock.
InjectionMocks
-You can set a mock in a private field regardless of @Autowired
Injection mock
- http://qiita.com/nyasba/items/16daeff7b9a2a65ef07f
- http://tech-blog.tsukaby.com/archives/305
- http://qiita.com/nyasba/items/cd72231f56536a9ef199
- http://javatechnology.net/java/mock-injectmocks/
DBUnit
--Note that if you do not prepare a DB schema for JUnit, the contents of the schema used in development may disappear if you interrupt it.
Private method exams are called by reflection
- http://qiita.com/village/items/2f0d99b25eef0c8fd4ec
--Sometimes I use JMockit
protected is easier to set with the build path
- http://qiita.com/stkdev/items/622e389e9387b75f99ad
Session (HTTP)
- https://codezine.jp/article/detail/7719
If you are using a method provided by the library, you may at worst check if the method itself is called.
Use fail () (Example :: When checking an abnormal system, you have to make an error when you go to the normal system