-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix for issue #499 Assumes in tests run by Theories #601
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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("A theory with no valid parameters did not fail.", 1, result.getFailureCount()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove the message? I find that in cases like this, it's hard to figure out whether the failure message indicates what should have happened correctly, or what did happen wrongly, and it's best to just let the assertion speak for itself. Thanks! |
||
|
||
} | ||
|
||
/** | ||
* 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) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put { on previous line. |
||
Assume.assumeTrue(value); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of stylistic things: