JUnit and MSTest

The implementation of each method test class, we need to do some initialization. Such as initialization applicationcontext. @Before using JUnit annotations.

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 and MSTest.

Junit

MSTest

-MSTest.TestFramework

-MS.VisualStudio.QualityTools.UnitTestFramework

 

Annotation / Annotation

Characteristics / Attribute

 

@RunWith

[TestClass]

Statement on the class.

Test class is declared a class (java naming test class is added after Test)

@BeforeClass

[ClassInitialize]

Statement on the method.

Test execution until all execution methods. (Junit required method must be static)

@Before

[TestInitialize]

Statement on the method.

Test performed before each method executes.

@Test

[Test Method]

Statement on the method.

Methods to Test Method Statement

@After

[TestCleanUp]

Statement on the method.

In the run after each Test method executed once

@AfterClass

[ClassCleanUp]

Statement on the method.

After the implementation of all Test method runs. (Junit required method must be static)

Guess you like

Origin www.cnblogs.com/buguge/p/11527368.html