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:
- Mac idea springboot project reported an error
- An error is reported when springboot starts: error creating bean with name ‘XXXX’
- The springboot integration mybatis reported an error. The parameter cannot be found
- About the error querying database. Cause: java.lang.nullpointerexception reported in mybatis
- After verifying parameters with validation, springboot reports an error: no constructor found in package name + class name
- Solution to the problem of spring boot running test class error creating bean with name ‘serverendpoint exporter’ defined
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- An error was reported when springboot connected to redis Servlet.service () for servlet [dispatcherServlet] in context with path [] threw e
- Self test error when springboot accesses es and starts
- Solve the problem of springboot and unit test starting applicationrunner
- import org.junit.Test And @ test error reporting — solutions
- Common forms of springboot2. X boot class location
- JMeter performance test monitoring server resource reported error: java.net.ConnectException : Connection refused: connect
- Junit4 unit test reports an error invalid project specified
- Eclipse:An error has occurred. See error log for more details. java.lang.NullPointerException
- The main class could not be found or loaded when springboot started
- Python normality test: test whether the data obey the normal distribution
- An error is reported when an android phone visits the app webpage: net::ERR_PROXY_CONNECTION_FAILED
- An error of 500 is reported when an item is assigned to a role
- When the mybatis field contains an expression, an error is reported when it is stored in the database