Spring整合JUnit单元测试

 

依赖spring的spring-test-4.2.4.RELEASE.jar包

测试代码:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.spring.demo04.UserService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo {
    
    @Autowired
    private UserService userService;
    
    @Test
    public void run() {
        userService.save();
    }

}

运行结果:

 

转载于:https://www.cnblogs.com/jumpkin1122/p/11623850.html

你可能感兴趣的:(java,测试)