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

Unit test UnsuccessfulWithDataPointFields#reportBadParams #1298

Open
alb-i986 opened this issue May 13, 2016 · 1 comment
Open

Unit test UnsuccessfulWithDataPointFields#reportBadParams #1298

alb-i986 opened this issue May 13, 2016 · 1 comment
Labels

Comments

@alb-i986
Copy link
Contributor

https://github.com/junit-team/junit4/blob/master/src/test/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java#L63

    @RunWith(Theories.class)
    public static class DoesntUseParams {
        @DataPoint
        public static int ONE = 1;

        @Theory
        public void everythingIsZero(int x, int y) {
            assertThat(2, is(3));
        }
    }

    @Test
    public void reportBadParams() throws Exception {
        assertThat(testResult(DoesntUseParams.class),
                hasSingleFailureContaining("everythingIsZero(\"1\" <from ONE>, \"1\" <from ONE>)"));
    }

The test is called "reportBadParams", which I guess is talking about the fact that the theory method everythingIsZero is not using the params x and y.
But it's not asserting anything about that specific fact.

Actually Theories doesn't seem to have any validation logic like that at all.

If you run the class DoesntUseParams, the theory fails with Caused by: java.lang.AssertionError: Expected: is <3> but: was <2>

org.junit.experimental.theories.internal.ParameterizedAssertionError: everythingIsZero("1" <from ONE>, "1" <from ONE>)

    at org.junit.experimental.theories.Theories$TheoryAnchor.reportParameterizedError(Theories.java:288)
    at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:237)
    at org.junit.experimental.theories.Theories$TheoryAnchor.runWithCompleteAssignment(Theories.java:260)
    at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:204)
    at org.junit.experimental.theories.Theories$TheoryAnchor.runWithIncompleteAssignment(Theories.java:212)
    at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:202)
    at org.junit.experimental.theories.Theories$TheoryAnchor.runWithIncompleteAssignment(Theories.java:212)
    at org.junit.experimental.theories.Theories$TheoryAnchor.runWithAssignment(Theories.java:202)
    at org.junit.experimental.theories.Theories$TheoryAnchor.evaluate(Theories.java:187)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:88)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:58)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
Caused by: java.lang.AssertionError: 
Expected: is <3>
     but: was <2>
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
    at org.junit.Assert.assertThat(Assert.java:960)
    at org.junit.Assert.assertThat(Assert.java:925)
    at org.junit.tests.experimental.theories.runner.UnsuccessfulWithDataPointFields$DoesntUseParams.everythingIsZero(UnsuccessfulWithDataPointFields.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:52)
    at org.junit.experimental.theories.Theories$TheoryAnchor$2.evaluate(Theories.java:274)
    at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:232)
    ... 21 more
@marcphilipp
Copy link
Member

I guess the test was written to ensure that the parameters are reported even though they are not used.

@dsaff Can you remember anything more specific?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants