Reference string annotation test method in maven project

1. Add the spring-test.jar package and Junit-test.jar to the pom file of the parent project

            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.version}</version>
                <scope>test</scope>
            </dependency>

2. Reinstall the parent project, otherwise an error will be reported when executing the run method

3. Create a test class and add annotations to the head of the class

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-*.xml")
public class UserTest {
    @Autowired
    private UserService userService;
    @Test
    public void test() {
        TUser user = new TUser();
        user.setAge(0);
        int addUser = userService.addUser(user);
        System.out.println(addUser);
    }

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325207600&siteId=291194637