亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JUnit 從 Suite 切換到 AllTests 導致注釋無法運行

JUnit 從 Suite 切換到 AllTests 導致注釋無法運行

江戶川亂折騰 2021-07-13 13:01:41
以前,我使用 Suite.class 指定要為具有以下結構方案的特定套件運行的測試: 套件@RunWith(Suite.class)@SuiteClasses({TC0.class, TC1.class...})public class mainTester {    @BeforeClass    public static void setUp() {//create xml report - create file, start xml structure}    @AfterClass    public static void tearDown(){//close xml report - close xml structure, close writer}測試@RunWith(Parameterized.class)public class TC0 extends testXMLReporter{    //Tests with params}最后testXMLReporter持有規則@Rulepublic TestRule watchman = new TestWatcher(){    //@Override apply, succeeded, failed to write custom xml structure for xml report}但是現在我需要創建套件來動態讀取文件中的數據,我從 Suite.class 切換到AllTests.class. 使其工作的唯一方法是更改我的套件 - 刪除@SuiteClasses - 將@RunWith值更改為AllTests.class - 并添加suite()方法public static TestSuite suite() {    TestSuite suite = new TestSuite();    for(Class<?> klass : CsvParser.readCSV()) {        suite.addTest(new junit.framework.JUnit4TestAdapter(klass));    }    return suite;}在讀取文件和運行測試方面運行良好,但現在突然間我的@Before/AfterClass 注釋以及@Rule沒有運行(我的報告不再創建)。這是什么原因,我該如何解決?
查看完整描述

1 回答

?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

最后我放棄了使用獨占AllTests.class,現在使用Suite.class調用AllTests.class. 例子:


主要的


Result result = JUnitCore.runClasses(intercessor.class);

代禱者


@RunWith(Suite.class)

@SuiteClasses({mainTester.class})

public class intercessor {

    //do Before & After

}

主測試器


@RunWith(AllTests.class)

public class mainTester {


    public static TestSuite suite() {

        TestSuite suite = new TestSuite();


        for(Class<?> klass : CsvParser.readCSV()) {

            suite.addTest(new junit.framework.JUnit4TestAdapter(klass));

        }


        return suite;

    }


}

希望它在未來對某人有所幫助


查看完整回答
反對 回復 2021-07-29
  • 1 回答
  • 0 關注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號