-1

I have @Theroy class as:

@Datapoints data1, data 2 ..... data 10 and,

@Theory
testMethod (data1, data2, data3) {
 //do testing
 exit from testMethod once testing is passed
}

I want to pass the testing exactly once, but not to run all the possible cases of datapoints.

Apparantly, i just want to test once, and exit to another test once passed.

I am not wishing System.exit() ... because I am not exiting jvm, but only that @Theory test is to be exit.

Thanks
mohan paudel
  • 27
  • 1
  • 4

2 Answers2

1
boolean passed = false;

@Theory
public void testMethods(Object data){
    assumeTrue(!passed);

    // testing here

    passed = true;
}

Use Assume which will skip tests without reporting a failure.

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

Didnot work for me, my case is :

boolean actual = false;
@Theory(nullsAccepted = false)
public void overlapIfFirstRangeEndsAfterSecondBegins(final Date start1,
        final Date end1, final Date start2, final Date end2) {
    // Assume ranges are valid
    Assume.assumeTrue(!actual);
    assumeThat(start1, before(end1));
    assumeThat(start2, before(end2));

    assumeThat(start1, onOrBefore(start2));
    assumeThat(end1,   onOrAfter(start2));

    actual = dateRangesOverlap(start1, end1, start2, end2);
    //this actual will be TRUE once when test is to be passed...then test must exit
}

Test case continued running....

And using assumeTrue made test case fail also. thanks

mohan paudel
  • 27
  • 1
  • 4
  • The way assumeThat works is that each test case is run but potentially skipped. If you are taking 4 arguments to your theory and there are 10 or more datapoints, this is a very large number of possible combinations of values to be passed to the Theory. The assumeThat runs against each of them. I suggest that Theory is not the way to do this. You might want to consider Parameterized. – John B Mar 27 '14 at 17:26
  • yea thanks...thats what i was thinking...after successing on all AssumeThat() conditions, and again successing in dateRangesOverlap()...that means first test is passed, right....now i wanted to exit from test and keep continue with another one... ... looks like theroy is playing bad role here.... – mohan paudel Mar 27 '14 at 21:49