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

error using JUnit4TestAdapter with class which has no test methods #226

orionll opened this Issue May 1, 2011 · 3 comments


None yet
3 participants

orionll commented May 1, 2011

Suppose we have two classes:

public class A

import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestResult;

public class Main
    public static void main(String[] args)
        Test test = new JUnit4TestAdapter(A.class);


        TestResult res = new TestResult();; // Running a test class with no tests??

If I run this application, Main class produces this output:


So, class A doesn't have any test methods, but JUnit4TestAdapter says that it does!


This comment has been minimized.

Boris-de commented May 14, 2013

Because the Test-Class contains no tests, so JUnit4TestAdapter uses a ErrorReportingRunner internally. This ErrorReportingRunner fills the Description-object with the cause-exception of the error. The countTestCases() actually sums the testCount() of the children of the Description, which in this case it one child. This child (the cause-description) contains no children of its own which is why testCount() assumes that it must be a test and returns 1. So in effect the Description returns a testCount() of 1 which is used by the Runner for countTestCases.

In this case this is confusing because the javadoc says that the method returns the number of tests.

For this error-case it seems to be wrong to assume that a leaf of the Description-tree is always a test, which is what isTest() currently does.

    public boolean isTest() {
        return getChildren().isEmpty();

This comment has been minimized.

Boris-de commented May 14, 2013

Browsing through more issues I noticed that there are more discussions that are related like #501 and especially #496 where the possible implications of a change to isTest() are discussed.


This comment has been minimized.


kcooney commented Sep 18, 2016

(doing a pass at closing old issues)

Given 1) JUnit 4-style tests were introduced a long time ago 2) JUnit 5 is around the corner and 3) this only affects an error case (a test case with no tests), I'm not sure it's worth fixing this

@kcooney kcooney closed this Sep 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment