@RunWith(SpringRunner.class)
@SpringBootTest
public class BankMainAppTest {
/**
* Test App load without throwing an exception.
*/
@Test
public void contextLoads() {
}//pass
@Test
public void applicationStarts() {
BankMainApp.main(new String[] {});
}//fail throw exception given below..
}
java.lang.IllegalArgumentException: Cannot instantiate factory class: org.springframework.boot.env.EnvironmentPostProcessor
Either annotate the test class with @SpringBootTest
and declare an empty test method or don't annotate the test class but invoke the main()
method in the test method.
But don't make both.
Here you do it and it starts one container (before the test execution) and then another one (in the method test).
Note that if you need to make no assertion because the test is only for the coverage rate, the idiom to use is the second way :
public class BankMainAppIT {
@Test
public void main() {
BankMainApp.main(new String[] {});
}
}
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.