I'm building a jar-with-dependencies that contains springboot classes and my test-classes too. my goal is to run my unit-test with Junit runner like this:
java -cp my-jar-with-dependencies.jar org.junit.runner.JUnitCore com.my.AppTest
heres a code:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class AppTest{
@Autowired
protected Serve1 app;
@Test
public void shouldAnswerWithTrue()
{
if(app == null){
System.out.println("IT IS NULL !!!!!!!");
}
else{
System.out.println(app.getB()); //prints BBBB!!!
}
}
When running this within maven surefire - all is great - (BBBB!!!) but when running with org.junit.runner.JUnitCore as described above, the @Autowired app has not being injected and I got: IT IS NULL !!!!!!!