Skip to content

Request.classes(newTestClass).getRunner().getDescription() #1320

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

Closed
Reissner opened this issue Jun 2, 2016 · 3 comments
Closed

Request.classes(newTestClass).getRunner().getDescription() #1320

Reissner opened this issue Jun 2, 2016 · 3 comments

Comments

@Reissner
Copy link

Reissner commented Jun 2, 2016

With a quite straightforward testclass annotated
@RunWith(Suite.class)
@SuiteClasses({
XMSectionTest.Basic.class
})
public class XMSectionTest {
...

I obtain for Request.classes(testClass).getRunner().getDescription() the value null,
whereas for Request.aClass(testClass).getRunner().getDescription()
I obtain eu.simuline.arithmetics.left2right.XMSectionTest
Hm,.... the first seems a bug to me,
whereas the second one.. seems to me at least uncomfortable,
because I think the description shall reflect the structure of the request and not its origin.

@marcphilipp
Copy link
Member

marcphilipp commented Jun 11, 2016

For the sake of a complete example:

@RunWith(Suite.class)
@SuiteClasses({
        XMSectionTest.Basic.class
})
public class XMSectionTest {
    public static class Basic {
        @Test
        public void test() {
            Assert.fail("foo");
        }
    }

    public static void main(String... args) {
        Class<?> testClass = XMSectionTest.class;

        System.out.println("Request.classes(testClass):");
        printTree(Request.classes(testClass).getRunner().getDescription());
        System.out.println();

        System.out.println("Request.aClass(testClass):");
        printTree(Request.aClass(testClass).getRunner().getDescription());
        System.out.println();
    }

    private static void printTree(Description description) {
        printTree(description, "- ");
    }
    private static void printTree(Description description, String indentation) {
        System.out.print(indentation);
        System.out.println(description + " (" + System.identityHashCode(description) + ")");
        for (Description child : description.getChildren()) {
            printTree(child, "  " + indentation);
        }
    }
}

Executing the main method prints:

Request.classes(testClass):
- null (1325547227)
  - org.junit.tests.XMSectionTest (980546781)
    - org.junit.tests.XMSectionTest$Basic (2061475679)
      - test(org.junit.tests.XMSectionTest$Basic) (140435067)

Request.aClass(testClass):
- org.junit.tests.XMSectionTest (1450495309)
  - org.junit.tests.XMSectionTest$Basic (1670782018)
    - test(org.junit.tests.XMSectionTest$Basic) (1706377736)

So, there is an intended difference: When using Request.classes there's an additional Description at the root of the hierarchy. Its display name is "null" because it doesn't have a test class associated with it. So the descriptor is not null but its toString() method returns the String "null".

Why would the second be "uncomfortable"?

@kcooney
Copy link
Member

kcooney commented Jul 17, 2016

I think it makes sense for the root Description node from Request.classes() has no class name, but it does seem weird that the toString() returns null. Can someone suggest a better string representation? Perhaps "classes"?

@kcooney kcooney added the bug label Jul 17, 2016
@marcphilipp
Copy link
Member

I think "classes" sounds good!

PeterWippermann added a commit to PeterWippermann/junit4 that referenced this issue Oct 24, 2016
PeterWippermann added a commit to PeterWippermann/junit4 that referenced this issue Oct 25, 2016
sebasjm pushed a commit to sebasjm/junit4 that referenced this issue Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants