2013-05-21 93 views
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有条件地运行测试方法

+0

你为什么要这么做?为什么不把方法放在方法体中呢? –

+1

开始[这里](http://stackoverflow.com/questions/13489388/how-junit-rule-works)。 –

+0

假设对于条件X,所有以上测试用例的执行都是不可取的(因为不合需要的测试用例失败)。对于X我只想要执行3个测试用例(全部都会成功)。如果我在方法体中添加一些条件(例如:假设为真),即使不需要的情况下也会执行成功。 – voldy

回答

4

使用JUnit的assume机制描述here。如果您想要驱动这两个条件,您将需要使用TheoriesParameterized以使JUnit执行多次。

+0

酷我会给一个镜头 – voldy