I got a NullPointerException when running JUnit and got stuck.
I should have Autowired on the non-test class side, but I get null.
Sample.java
public class Sample{
@Autowired
private Hoge hoge; //← null at test execution
/**The following method*/
}
On the test code side, it wasn't Autowired.
SampleTest.java
public class SampleTest{
@Autowired
private Hoge hoge; //I forgot
/**The following method*/
}
It will be injected when Spring is executed, so I thought I didn't have to worry about it, but I have to declare it on the test side as well.