spring单元测试框架

pom.xml:

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.3.17.RELEASE</version>
            <scope>test</scope>
        </dependency>

测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-config.xml")
public class TestSprintTest {
    @Autowired
    private SuperMan sm;//要测试的对象,自动完成对象的创建和装配
    @Autowired
    private ApplicationContext factory;
    @Autowired
    private A a;
    @Test
    public void testSuperMan(){
        sm.fly();
    }
    @Test
    public void testA(){
        a.testA();
    }
}

猜你喜欢

转载自blog.csdn.net/Ting1king/article/details/107582047