I dont have any error and tests run successfully when its run as Junit. But on Building that project’s pom, the following error is coming and the build is being failed because of these test failure.
org.mockito.exceptions.misusing.InjectMocksException:
cannot instantiate @InjectMocks field named ‘commissioner’ of type ‘com.project.Commissioner’. You have’nt provided the instance at field declaration so I tried to construct the instance.
However the constructor or the initialization block threw an Exception at com.project.CommissionerTest.setUp
Caused by : java.lang.ExceptionInInitializerError : Exception java.lang.ExceptionInInitializerError [in thread “main”]
This is the Error report of individual tests. but the failing of @InjectMocks happens only when building and when on test, its perfectly fine. Also setUp is in before
@Before
public void setUp throws Exception()
{
MockitoAnnotations.openMocks(this);
}
its Junit 4 and the dependency for mockito is
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
</dependency>
How come the exception is happening only on building and not on actual junit run. On Junit run, every test is passed.