• JUnit与MSTest


    执行test类的每个方法时,需要做一些初始化。比如初始化applicationcontext。JUnit使用@Before注解。

    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.context.ApplicationContext;
    import org.springframework.test.context.junit4.SpringRunner;
    
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    @Slf4j
    public class PageProcessorTest {
        @Autowired
        OrderList0Processor orderList0Processor;
        @Autowired
        ApplicationContext applicationContext;
        
        @Before
        public void init(){
            System.out.println("this is @Before");
            ApplicationContextUtils.setContext(applicationContext);
        }
        
        @Test
        public void spiderT0() {
    
    //        ApplicationContextUtils.setContext(applicationContext);
            orderList0Processor.startSpider(2);
            log.info("当前页数:{}", orderList22Processor.getPageSize());
        }
    }

    JUnit与MSTest。

    Junit

    MSTest

    -MSTest.TestFramework

    -MS.VisualStudio.QualityTools.UnitTestFramework

    注解/Annotation

    特性/Attribute

    @RunWith

    [TestClass]

    声明在class上。

    声明一个class为Test类(java命名规范是在被测试类后加Test)

    @BeforeClass

    [ClassInitialize]

    声明在方法上。

    在所有Test方法执行前执行。(junit要求方法必须是静态的)

    @Before

    [TestInitialize]

    声明在方法上。

    在每个Test方法执行前执行。

    @Test

    [TestMethod]

    声明在方法上。

    声明方法为Test方法

    @After

    [TestCleanUp]

    声明在方法上。

    在每个Test方法运行后被执行一次

    @AfterClass

    [ClassCleanUp]

    声明在方法上。

    在所有Test方法运行后执行。(junit要求方法必须是静态的)

  • 相关阅读:
    ALLTOALL在线格式转换
    navicat注册码(亲测可用)
    抓包工具Fiddler设置(IOS)
    第三方设备云接入小米IOT平台
    snowboy进行语音唤醒,编译snowboy文件
    微信公众号开发之调起拍照或从手机相册中选图接口
    开放API网关实践
    分布式服务限流实战,已经为你排好坑了
    注解@PostConstruct与@PreDestroy使用讲解
    [转]布隆过滤器过时了,未来属于布谷鸟过滤器?
  • 原文地址:https://www.cnblogs.com/buguge/p/11527368.html
Copyright © 2020-2023  润新知