Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #499 Assumes in tests run by Theories #601

Merged
merged 2 commits into from
Jan 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/org/junit/experimental/theories/Theories.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ private TestClass getTestClass() {
public void evaluate() throws Throwable {
runWithAssignment(Assignments.allUnassigned(
fTestMethod.getMethod(), getTestClass()));

if (successes == 0) {

//if this test method is not annotated with Theory, then no successes is a valid case
boolean hasTheoryAnnotation = fTestMethod.getAnnotation(Theory.class) != null;
if (successes == 0 && hasTheoryAnnotation) {
Assert
.fail("Never found parameters that satisfied method assumptions. Violated assumptions: "
+ fInvalidParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.junit.tests.experimental.theories;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runners.model.InitializationError;

@RunWith(Theories.class)
public class AssumingInTheoriesTest {

@Test
public void noTheoryAnnotationMeansAssumeShouldIgnore() {
Assume.assumeTrue(false);
}

@Test
public void theoryMeansOnlyAssumeShouldFail() throws InitializationError {
JUnitCore junitRunner = new JUnitCore();
Runner theoryRunner = new Theories(TheoryWithNoUnassumedParameters.class);
Request request = Request.runner(theoryRunner);
Result result = junitRunner.run(request);
Assert.assertEquals(1, result.getFailureCount());
}

/**
* Simple class that SHOULD fail because no parameters are met.
*/
public static class TheoryWithNoUnassumedParameters {

@DataPoint
public final static boolean FALSE = false;

@Theory
public void theoryWithNoUnassumedParameters(boolean value) {
Assume.assumeTrue(value);
}
}

}