The springboot test class reported an error NullPointerException

The test class should be annotated @ runwith (springrunner. Class)
the significance of the annotation is that the test class should use the injected class, such as the class injected by @ Autowired,

With @ runwith (springrunner. Class), these classes can be instantiated into the spring container, and automatic injection can take effect,

Otherwise, just a NullPointerException

@SpringBootTest
@RunWith(SpringRunner.class)
public class AppTest
{
    @Autowired
    private Sender sender;

    @Test
    public void Sendtest(){

        System.out.println(Sender.class+""+sender);
        sender.send();


    }
}

You can still run without @ runwith in the idea because it is recognized as a JUnit running environment in the idea, which is equivalent to a self recognized runwidth environment configuration. But not in other ides. Therefore, in order that your code can run normally in other ides, it is recommended to add @ runwith (springrunner. Class)

Read More: