thphuoc / junitparams

Automatically exported from code.google.com/p/junitparams
0 stars 0 forks source link

With assumption failure, runner sends suite descriptions to RunListener, instead of test descriptions #49

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Run the script shown at the bottom
i.e.
1. Add a RunListener to an instance of JUnitCore
2. Run a parameterised test with N parameters
3. Let all tests fail by putting an assumeTrue(false) in an @Before block
4. look at all descriptions passed to testAssumptionFailure

What is the expected output? What do you see instead?
Expected either:
A. One suite description, describing all N the parameter tests for that 
particular test.
B. One test description for each of the N parameters

Actual:
A full suite description of N tests, N times

The standard JUnit runner passes what would be B, test descriptions for 
assumption failed tests.

What version of the product are you using? On what operating system?
Version: 1.0.2
OS: Windows 7 Pro SP1
Java: 1.7.0_21
JUnit: 4.11

Please provide any additional information below.

These are the descriptions from
org.junit.runner.notification.Failure#getDescription passed to 
RunListener#testAssumptionFailure by
As you can see, repetition of descriptions

====== The Output ======

description:
    className: com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest
    displayName: normal(com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest)
    methodName: normal
    testCount: 1
    isEmpty: false
    isSuite: false
    isTest: true
        annotation:
        @org.junit.Test(expected=class org.junit.Test$None, timeout=0)
description:
    className: parameterised
    displayName: parameterised
    methodName: null
    testCount: 2
    isEmpty: false
    isSuite: true
    isTest: false
        Child description:
        className: com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest
        displayName: [0] true (parameterised)(com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest)
        methodName: [0] true (parameterised)
        testCount: 1
        isEmpty: false
        isSuite: false
        isTest: true
            annotation:
            @org.junit.Test(expected=class org.junit.Test$None, timeout=0)
            annotation:
            @junitparams.Parameters(source=interface javax.lang.model.type.NullType, value=[true, false], method=)
        Child description:
        className: com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest
        displayName: [1] false (parameterised)(com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest)
        methodName: [1] false (parameterised)
        testCount: 1
        isEmpty: false
        isSuite: false
        isTest: true
            annotation:
            @org.junit.Test(expected=class org.junit.Test$None, timeout=0)
            annotation:
            @junitparams.Parameters(source=interface javax.lang.model.type.NullType, value=[true, false], method=)
description:
    className: parameterised
    displayName: parameterised
    methodName: null
    testCount: 2
    isEmpty: false
    isSuite: true
    isTest: false
        Child description:
        className: com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest
        displayName: [0] true (parameterised)(com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest)
        methodName: [0] true (parameterised)
        testCount: 1
        isEmpty: false
        isSuite: false
        isTest: true
            annotation:
            @org.junit.Test(expected=class org.junit.Test$None, timeout=0)
            annotation:
            @junitparams.Parameters(source=interface javax.lang.model.type.NullType, value=[true, false], method=)
        Child description:
        className: com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest
        displayName: [1] false (parameterised)(com.phlexglobal.tests.external.JUnitParamsAssumeBeforeTest)
        methodName: [1] false (parameterised)
        testCount: 1
        isEmpty: false
        isSuite: false
        isTest: true
            annotation:
            @org.junit.Test(expected=class org.junit.Test$None, timeout=0)
            annotation:
            @junitparams.Parameters(source=interface javax.lang.model.type.NullType, value=[true, false], method=)

====== The Test Script ======

package com.phlexglobal.tests.external;

import java.lang.annotation.Annotation;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

@RunWith(JUnitParamsRunner.class)
public class JUnitParamsAssumeBeforeTest {

    public static void main(String args[]) {
        JUnitCore unitcore = new JUnitCore();
        unitcore.addListener(listener);
        unitcore.run(JUnitParamsAssumeBeforeTest.class);
    }

    public static RunListener listener = new RunListener() {
        @Override
        public void testAssumptionFailure(Failure failure) {
            System.out.println(new DescriptionRep().reprDescription(failure.getDescription()));
        }
    };

    @Before
    public void doSomeCheck() {
        assumeTrue(false);
    }

    @Test
    @Parameters({ "true", "false" })
    public void parameterised(boolean value) {
        System.out.println("assumeOnceWorksAndOnceIgnores: " + value);
        assertTrue(value);
    }

    @Test
    public void normal() {
        System.out.println("anotherTest");
        assertTrue(false);
    }

    private static class DescriptionRep {

        private StringBuffer repPrefix = new StringBuffer("\n\t");

        private String reprDescription(Description description) {
            StringBuilder sb = new StringBuilder("description:");
            sb.append(repPrefix + "className: " + description.getClassName());
            sb.append(repPrefix + "displayName: " + description.getDisplayName());
            sb.append(repPrefix + "methodName: " + description.getMethodName());
            sb.append(repPrefix + "testCount: " + description.testCount());
            sb.append(repPrefix + "isEmpty: " + description.isEmpty());
            sb.append(repPrefix + "isSuite: " + description.isSuite());
            sb.append(repPrefix + "isTest: " + description.isTest());

            repPrefix.append('\t'); //increase indentation

            for (Annotation a : description.getAnnotations())
                sb.append(repPrefix).append(repAnnotation(a));

            repPrefix.deleteCharAt(repPrefix.length()-1); //decrease indentation

            repPrefix.append('\t'); //increase indentation

            for (Description d : description.getChildren())
                sb.append(repPrefix + "Child ").append(reprDescription(d));

            repPrefix.deleteCharAt(repPrefix.length()-1); //decrease indentation

            return sb.toString();
        }

        private String repAnnotation(Annotation a) {
            StringBuilder sb = new StringBuilder("annotation:");
            sb.append(repPrefix + "" + a.toString());
            return sb.toString();
        }
    }
}

Original issue reported on code.google.com by golding...@gmail.com on 14 Aug 2013 at 12:02

GoogleCodeExporter commented 8 years ago

Original comment by lipinski...@gmail.com on 26 Oct 2013 at 4:13

GoogleCodeExporter commented 8 years ago
That's what i'm getting now:
description:
    className: junitparams.AssumptionsTest
    displayName: normal(junitparams.AssumptionsTest)
    methodName: normal
    testCount: 1
    isEmpty: false
    isSuite: false
    isTest: true
        annotation:
        @org.junit.Test(timeout=0, expected=class org.junit.Test$None)
description:
    className: junitparams.AssumptionsTest
    displayName: [0] true (parameterised)(junitparams.AssumptionsTest)
    methodName: [0] true (parameterised)
    testCount: 1
    isEmpty: false
    isSuite: false
    isTest: true
        annotation:
        @org.junit.Test(timeout=0, expected=class org.junit.Test$None)
        annotation:
        @junitparams.Parameters(method=, value=[true, false], source=interface javax.lang.model.type.NullType)
description:
    className: junitparams.AssumptionsTest
    displayName: [1] false (parameterised)(junitparams.AssumptionsTest)
    methodName: [1] false (parameterised)
    testCount: 1
    isEmpty: false
    isSuite: false
    isTest: true
        annotation:
        @org.junit.Test(timeout=0, expected=class org.junit.Test$None)
        annotation:
        @junitparams.Parameters(method=, value=[true, false], source=interface javax.lang.model.type.NullType)

Original comment by lipinski...@gmail.com on 28 Jul 2014 at 9:08