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);
    }
}

Above is my Test case. based on two cases i want to execute set of above test methods.

For eg:

  1. On Condition X, only checkInPathFolder(), checkCustomObjectExists(), runSwift() should be executed.
  2. On Condition Y, checkInPathFolder(), runSwift(), checkExceptionFolder() should be executed.
Sangam Belose
  • 4,262
  • 8
  • 26
  • 48
voldy
  • 359
  • 1
  • 8
  • 21
  • Why would you want to do this? Why not just put the condidition in the method body? – Joeri Hendrickx May 21 '13 at 11:05
  • 1
    Start [here](http://stackoverflow.com/questions/13489388/how-junit-rule-works). – Boris the Spider May 21 '13 at 11:05
  • suppose for a condition X all above test cases execute which is not desirable(as undesirable test cases fail). for for X i want only 3 test cases to be executed(all will be successful). if i put some condition (eg: Assume true) in method body even undesired cases execute as success. – voldy May 21 '13 at 11:09
  • Does it really matter if a test that should not have been run, runs with success? – John B May 21 '13 at 11:13
  • yeah, thts the main issse. if it was not a matter of concern, Assert.assertTrue(false) works – voldy May 21 '13 at 11:18

1 Answers1

4

Use JUnit's assume mechanism described here. You will need to use either Theories of Parameterized to cause JUnit to execute more than once if you want to drive those two conditions.

Community
  • 1
  • 1
John B
  • 32,493
  • 6
  • 77
  • 98