簡體   English   中英

如何僅在達到特定測試之前運行junit測試

[英]How do you run junit tests only till a particular test is reached

我有一堆依賴的測試用例(不依賴於dependsOn參數),並且一次不能運行一個測試。 這就是為什么我要運行測試直到達到特定測試的原因。 我想停止執行進一步的測試,並希望進行拆卸。

有辦法嗎?

您可以通過org.junit.Assume.assumeTrue(condition)控制測試用例的執行,如果發現條件為假,它將忽略測試用例。 在開始時將條件設置為true,例如,可以使用用戶一個私有的靜態布爾變量,在要執行的最后一個測試用例的結尾將條件設置為false。 檢查@BeforeTest中的條件。

樣例代碼

private static boolean runTest = true;

@org.junit.Before
public void before() throws Exception {
    org.junit.Assume.assumeTrue(runTest);
}

@org.junit.Test
public void test1() throws Exception {
    // will be executed
}

@org.junit.Test
public void test2() throws Exception {
    // will be executed
}

@org.junit.Test
public void test3() throws Exception {
    // will be executed
    runTest = false;
    // no test after this will be executed
}

@org.junit.Test
public void test4() throws Exception {

    // will be ignored

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM