当前位置: 移动技术网 > IT编程>开发语言>Java > JUnit与MSTest

JUnit与MSTest

2019年09月16日  | 移动技术网IT编程  | 我要评论

执行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要求方法必须是静态的)

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网