Using @Autowired annotation to generate nullpointer in unit test
terms of settlement
1. Introduce POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
2. Add notes to the unit test
@SpringBootTest(classes = EduApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class redisTemplate {
@Autowired
RedisTemplate redisTemplate;
@Test
public void testStringAdd(){
BoundValueOperations str = redisTemplate.boundValueOps("str");
// Set the value via redisTemplate
str.set("test1");
str.set("test2");
}
}
Read More:
- import org.junit.Test And @ test error reporting — solutions
- Spring configuration transaction, JUnit unit test error “failed to load ApplicationContext”
- Maven skip unit test
- Maven skip unit test- maven.test.skip And skipstests
- Solve the problem of springboot and unit test starting applicationrunner
- The usage of Java JUnit unit test and the solution of initialization error
- Unit automatically delete the resources under the unreferenced assets
- Junit4 unit test reports an error invalid project specified
- Multithreading: when doing unit test, use thread pool to find that the specified code is not running and skip directly
- Error in idea unit test command line is too long
- The springboot test class reported an error NullPointerException
- Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test)
- Python normality test: test whether the data obey the normal distribution
- Solution to the problem of spring boot running test class error creating bean with name ‘serverendpoint exporter’ defined
- Mybatis-plus automatically generates code error [Solved]
- Failed to retrieve platformtransactionmanager for @ transactional test: [defaulttest]
- Springboot: start error reporting after introducing paging plug-in PageHelper
- Maven project pom.xml Solutions to error reporting
- Error reporting – the project directly introduces the error reporting and solution of. SCSS file
- Vivado Error: (vlog-7) Failed to open design unit file