Tag Archives: Junit tests

[Solved] Initialization error encountered by JUnit unit test: Method initialization error not found


The reasons may be as follows:
1. Methods with return values cannot be tested directly
2. Methods with parameters cannot be directly tested
3. Methods with access rights under public cannot be directly tested
Static static methods cannot be directly tested
5. Do not add an @test annotation to any of the first four conditions, or an initializationError will occur to any method that meets the @test condition


Only the methods of public void can be tested using @test

Point one: must be public, the following are not allowed
Point two: must be void, no return value, without any modification final, static, etc.

Many bloggers say it could be the lead pack problem:
in addition to introducing junit-4.12.jar, two dependent jars were introduced: hamcrest-core-1.3.rc2.jar, and hamcrest-library-1.3.rc2.jar
(Note: After personal testing, this is usually not the case.)