1
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
public class SwiftTest {
SwiftUtil swiftUtil = new SwiftUtil();
boolean result;
@Test
public void checkInPathFolder()
{
result = swiftUtil.checkInPathFolder();
assertTrue(result);
}
@Test
public void checkCustomObjectExists()
{
result=swiftUtil.validateWFId();
assertTrue(result);
}
@Test
public void runSwift()
{
result=swiftUtil.runSwiftBatch();
assertTrue(result);
}
@Test
public void checkTreatedFolder()
{
result=swiftUtil.checkTreatedFolder();
assertTrue(result);
}
@Test
public void checkExceptionFolder()
{
result=swiftUtil.checkExceptionFolder();
assertTrue(result);
}
}
以上是我的測試案例。基於兩種情況我想執行一組上述測試方法。 例如:在條件X上,只應執行checkInPathFolder(),checkCustomObjectExists(),runSwift()。在條件Y上,checkInPathFolder(),runSwift(),checkExceptionFolder()應該被執行。JUnit有條件地運行測試方法
你爲什麼要這麼做?爲什麼不把方法放在方法體中呢? –
開始[這裏](http://stackoverflow.com/questions/13489388/how-junit-rule-works)。 –
假設對於條件X,所有以上測試用例的執行都是不可取的(因爲不合需要的測試用例失敗)。對於X我只想要執行3個測試用例(全部都會成功)。如果我在方法體中添加一些條件(例如:假設爲真),即使不需要的情況下也會執行成功。 – voldy