JUnitのとMSTestを

各メソッドのテストクラスの実装では、我々はいくつかの初期化を行う必要があります。このような初期化のApplicationContextとして。JUnitの注釈を使用して@Before。

輸入org.junit.Before;
輸入org.junit.Test;
輸入org.junit.runner.RunWith;
輸入org.springframework.beans.factory.annotation.Autowired;
輸入org.springframework.boot.test.context.SpringBootTest;
輸入org.springframework.context.ApplicationContext;
輸入org.springframework.test.context.junit4.SpringRunner。


@RunWith(SpringRunner。クラス
@SpringBootTest 
@ SLF4J 
パブリック クラスPageProcessorTest { 
    @Autowired 
    OrderList0Processor orderList0Processor。
    @Autowired 
    のApplicationContextのApplicationContext。
    
    @Before 
    公共 ボイドのinit(){ 
        System.out.printlnは( "これは@Beforeです" )。
        ApplicationContextUtils.setContext(ApplicationContextの)。
    } 
    
    @Test 
    公共 ボイドspiderT0(){ 

//         ApplicationContextUtils.setContext(ApplicationContextの); 
        orderList0Processor.startSpider(2 )。
        log.info( "当前页数:{}" 、orderList22Processor.getPageSize())。
    } 
}

 

 

JUnitのとMSTestを。

JUnitの

MSTestを

-MSTest.TestFramework

-MS.VisualStudio.QualityTools.UnitTestFramework

 

注釈/注釈

特性/属性

 

@RunWith

[TestClassを】

クラスの声明。

テストクラスは、クラス(テストクラスはテスト後に追加されたJavaの命名)が宣言されています

@BeforeClass

[ClassInitialize]

方法に関する声明。

すべての実行方法までテスト実行。(JUnitの必須メソッドは静的でなければなりません)

@前

[TestInitialize]

方法に関する声明。

それぞれの方法が実行される前にテストを行います。

@テスト

[試験方法]

方法に関する声明。

METHODステートメントをテストする方法

@After

[TestCleanUp]

方法に関する声明。

一度実行された各試験方法の後に実行で

@放課後

[ClassCleanUp]

方法に関する声明。

すべての試験方法の実行の実装後。(JUnitの必須メソッドは静的でなければなりません)

おすすめ

転載: www.cnblogs.com/buguge/p/11527368.html