JUnit errors

A unit testing framework for Java

http://junit.org
Solution coverage:
Summary coverage:

Top patterns

  1. JUnit test assertion failed

    AssertionError is thrown when using JUnit's internal assertions methods compare two different values and those are not equal. Also, the developer can invoke the method when the test logic fails.

    The simplest code to reproduce the error is the following:

    import static org.junit.Assert.fail;
    
    public class FailTest { 
    
       @Test 
       public void shouldAssertFail() { 
          ...
          if( ... ) {
             fail("Any message");
          }
       } 
    }
    

    Mind the static import. The fail is part of the JUnit API.

    Your best course of action is to use the debugger to see why the test is failing and what is the condition that is not being met.

  2. JUnit "equals" comparison failed

    ComparisonFailure is thrown when using JUnit's internal assertions to compare two strings, number or objects that are not equal. The simplest code to reproduce the error is the following:

    import static org.junit.Assert.assertEquals;
    
    public class ObjectComparisonTest { 
    
       @Test 
       public void shouldAssertStrings() { 
          assertEquals("Jhon", "John");  //The letters are in different order
       } 
    
       @Test 
       public void shouldAssertNumbers() { 
          assertEquals(1, 2); 
       } 
    
       @Test 
       public void shouldAssertObjects() {
          Person p1 = new Person();
          Person p2 = new Person();
          assertEquals(p1, p2);  // The object instances are not the same
       } 
    }
    
    class Person { ... }
    

    Mind the static import. The assertEquals is part of the JUnit API.

  3. Unexpected exception was thrown

    When you test your code, you not only test the successful cases, you also must test the failure cases when an exception is thrown.

    @Test(expect = MyException.class)
    public void testCase() {
       ...
       throw new AnotherException();
    }
    

    In this example, the test case is waiting for the code throws MyException but the code is throwing AnotherException.


DescriptionException TypeEntry MethodWeb pages

JUnit test assertion failed

java.lang.AssertionError
org.junit.Assert.fail
4163Web pages
1Solution
AssertionErrorAssert.fail4163

JUnit "equals" comparison failed

org.junit.ComparisonFailure
org.junit.Assert.assertEquals
652Web pages
1Solution
ComparisonFailureAssert.assertEquals652

Unexpected exception was thrown

java.lang.Exception
org.junit.internal.runners.statements.ExpectException.evaluate
73Web pages
1Solution
ExceptionExpectException.evaluate73

JUnit - No runnable methods

java.lang.Exception
org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods
72Web pages
1Solution
ExceptionBlockJUnit4ClassRunner.validateInstanceMethods72

Unexpected exception was thrown

java.lang.AssertionError
org.junit.internal.runners.statements.ExpectException.evaluate
59Web pages
1Solution
AssertionErrorExpectException.evaluate59

No tests method found running test via proxy

java.lang.Exception
org.junit.internal.requests.FilterRequest.getRunner
57Web pages
ExceptionFilterRequest.getRunner57

JUnit and Hamcrest with "assertThat" comparison failed

java.lang.AssertionError
org.junit.Assert.assertThat
47Web pages
1Solution
AssertionErrorAssert.assertThat47

TestRunner and BaseTestRunner show a Stub error message

java.lang.RuntimeException
3 frames hidden
junit.textui.TestRunner.<init>
28Web pages
1Solution
RuntimeExceptionTestRunner.<init>28

Test class should have exactly one public zero-argument constructor

java.lang.Exception
1 frames hidden
org.junit.runners.BlockJUnit4ClassRunner.validateConstructor
24Web pages
1Solution
ExceptionBlockJUnit4ClassRunner.validateConstructor24

JUnit Runner class not found when using JMockit

java.lang.NoClassDefFoundError
1 frames hidden
org.junit.internal.requests.ClassRequest.getRunner
18Web pages
1Solution
NoClassDefFoundErrorClassRequest.getRunner18

InitializationError

java.lang.Exception
org.junit.runners.model.InitializationError.<init>
16Web pages
1Solution
ExceptionInitializationError.<init>16

NullPointerException using hadoop-common-project

java.lang.NullPointerException
17 frames hidden
org.junit.runners.ParentRunner.run
16Web pages
1Solution
NullPointerExceptionParentRunner.run16

@Test, @Before, @After, @BeforeClass and @AfterClass rules

java.lang.Exception
org.junit.runners.model.FrameworkMethod.validatePublicVoid
12Web pages
1Solution
ExceptionFrameworkMethod.validatePublicVoid12

JUnit and Hamcrest with "Assume.assumeThat" comparison failed

org.junit.AssumptionViolatedException
org.junit.Assume.assumeThat
11Web pages
1Solution
AssumptionViolatedExceptionAssume.assumeThat11

ParentRunner has thrown a NoSuchFieldError

java.lang.NoSuchFieldError
org.junit.runners.ParentRunner.<init>
10Web pages
1Solution
NoSuchFieldErrorParentRunner.<init>10

Test class should have exactly one public constructor

java.lang.Exception
org.junit.runners.BlockJUnit4ClassRunner.validateOnlyOneConstructor
10Web pages
1Solution
ExceptionBlockJUnit4ClassRunner.validateOnlyOneConstructor10

Test class must have only one constructor

java.lang.IllegalArgumentException
org.junit.runners.model.TestClass.<init>
9Web pages
1Solution
IllegalArgumentExceptionTestClass.<init>9

ParentRunner has thrown an InitializationError

org.junit.runners.model.InitializationError
1 frames hidden
org.junit.runners.ParentRunner.<init>
8Web pages
1Solution
InitializationErrorParentRunner.<init>8

RuntimeException in MethodRoadie.runBeforesThenTestThenAfters()

java.lang.RuntimeException
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters
8Web pages
1Solution
RuntimeExceptionMethodRoadie.runBeforesThenTestThenAfters8

ArrayIndexOutOfBoundsException using AMBARI project

org.apache.maven.surefire.testset.TestSetFailedException
10 frames hidden
org.junit.runner.notification.RunNotifier.fireTestFailure
8Web pages
1Solution
TestSetFailedExceptionRunNotifier.fireTestFailure8

Test method should have no parameters

java.lang.Exception
org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg
7Web pages
1Solution
ExceptionFrameworkMethod.validatePublicVoidNoArg7

JUnit "Assert.assertTrue" and "Assert.assertFalse" comparison failed

javax.ejb.EJBException
1 frames hidden
org.junit.Assert.assertTrue
7Web pages
1Solution
EJBExceptionAssert.assertTrue7

JUnit "Assert.assertArrayEquals" comparison failed

org.junit.internal.ArrayComparisonFailure
2 frames hidden
org.junit.Assert.assertArrayEquals
6Web pages
1Solution
ArrayComparisonFailureAssert.assertArrayEquals6

PowerMock and javassist conflict versions

java.lang.NoSuchMethodError
23 frames hidden
org.junit.internal.requests.ClassRequest.getRunner
6Web pages
1Solution
NoSuchMethodErrorClassRequest.getRunner6

Field with @Rule annotation must be public

java.lang.Exception
org.junit.internal.runners.rules.RuleFieldValidator.addError
6Web pages
1Solution
ExceptionRuleFieldValidator.addError6

spring-test and JUnit conflict versions

java.lang.IllegalStateException
10 frames hidden
org.junit.internal.requests.ClassRequest.getRunner
6Web pages
1Solution
ExceptionInInitializerErrorClassRequest.getRunner6

Hamcrest has thrown a NoSuchMethodError

java.lang.NoSuchMethodError
7 frames hidden
org.junit.Assert.assertThat
6Web pages
1Solution
NoSuchMethodErrorAssert.assertThat6

NullPointerException: Cannot invoke method finish()

java.lang.NullPointerException
2 frames hidden
org.junit.runner.notification.RunNotifier.fireTestRunFinished
6Web pages
1Solution
NullPointerExceptionRunNotifier.fireTestRunFinished6

The temporary folder has not yet been created when call TemporaryFolder.getRoot()

java.lang.IllegalStateException
org.junit.rules.TemporaryFolder.getRoot
5Web pages
IllegalStateExceptionTemporaryFolder.getRoot5

JUnit Description cannot create Suite Description

java.lang.NullPointerException
org.junit.runner.Description.createSuiteDescription
5Web pages
NullPointerExceptionDescription.createSuiteDescription5

Hadoop cannot initialize Cluster

java.io.IOException
13 frames hidden
junit.framework.TestSuite.run
5Web pages
1Solution
IOExceptionTestSuite.run5

DecisionTreeException in MOTECH project

org.motechproject.decisiontree.server.service.DecisionTreeServerImpl$DecisionTreeException
12 frames hidden
org.junit.internal.runners.statements.RunBefores.evaluate
5Web pages
1Solution
DecisionTreeServerImpl$DecisionTreeExceptionRunBefores.evaluate5

Cucumber conflict versions

java.lang.NoSuchMethodError
11 frames hidden
org.junit.internal.requests.ClassRequest.getRunner
4Web pages
1Solution
NoSuchMethodErrorClassRequest.getRunner4

Heritrix3 exception with illegal character

java.lang.IllegalArgumentException
18 frames hidden
junit.framework.TestSuite.run
4Web pages
1Solution
IllegalArgumentExceptionTestSuite.run4

JUnit parametrized methods should be "public" and "static"

java.lang.Exception
org.junit.runners.Parameterized.getParametersMethod
4Web pages
1Solution
ExceptionParameterized.getParametersMethod4

IllegalArgumentException in k3po library

java.lang.IllegalArgumentException
2 frames hidden
org.junit.rules.Verifier$1.evaluate
4Web pages
1Solution
IllegalArgumentExceptionVerifier$1.evaluate4

JUnit3 running with JUnit4

junit.framework.AssertionFailedError
org.junit.internal.runners.JUnit38ClassRunner.run
4Web pages
1Solution
AssertionFailedErrorJUnit38ClassRunner.run4

Error processing shell arguments with GWT/GWTP

com.google.gwt.junit.JUnitFatalLaunchException
10 frames hidden
junit.framework.TestSuite.run
4Web pages
1Solution
JUnitFatalLaunchExceptionTestSuite.run4

IllegalArgumentException using robolectric library

java.lang.IllegalArgumentException
14 frames hidden
org.junit.runners.ParentRunner.run
3Web pages
1Solution
IllegalArgumentExceptionParentRunner.run3

Generic RuntimeException

java.lang.RuntimeException
junit.framework.TestCase.runBare
3Web pages
1Solution
RuntimeExceptionTestCase.runBare3

NullPointerException in kafka project

java.lang.NullPointerException
9 frames hidden
org.junit.rules.ExternalResource$1.evaluate
3Web pages
1Solution
NullPointerExceptionExternalResource$1.evaluate3

Mockito conflict versions

java.lang.NoSuchMethodError
10 frames hidden
org.junit.internal.requests.ClassRequest.getRunner
3Web pages
1Solution
NoSuchMethodErrorClassRequest.getRunner3

TestTimedOutException in gateway project

org.junit.runners.model.MultipleFailureException
2 frames hidden
org.junit.internal.runners.statements.FailOnTimeout.evaluate
3Web pages
1Solution
MultipleFailureExceptionFailOnTimeout.evaluate3

JUnit and Hamcrest with "Assume.assumeTrue" and "Assume.assumeFalse" comparison failed

org.junit.AssumptionViolatedException
org.junit.Assume.assumeTrue
3Web pages
1Solution
AssumptionViolatedExceptionAssume.assumeTrue3

Instances haven't been shut down with hazelcast library

java.lang.IllegalStateException
4 frames hidden
org.junit.runners.ParentRunner$3.run
3Web pages
1Solution
IllegalStateExceptionParentRunner$3.run3

casandra-unit and casandra-unit-spring conflict versions

java.lang.NoSuchMethodError
3 frames hidden
org.junit.rules.RunRules.evaluate
3Web pages
NoSuchMethodErrorRunRules.evaluate3

JUnitParamsRunner with wrong JUnit version

java.lang.RuntimeException
10 frames hidden
org.junit.runners.ParentRunner$2.evaluate
3Web pages
1Solution
RuntimeExceptionParentRunner$2.evaluate3

Unexpected NullPointerException was thrown, expected IllegalArgumentException

java.lang.Exception
1 frames hidden
org.junit.internal.runners.BeforeAndAfterRunner.runProtected
3Web pages
1Solution
ExceptionBeforeAndAfterRunner.runProtected3

IllegalArgumentException using Commons VFS library

java.io.IOException
29 frames hidden
org.junit.runners.ParentRunner.run
3Web pages
1Solution
IllegalArgumentExceptionParentRunner.run3

Robolectric conflict versions

java.lang.NoSuchMethodError
4 frames hidden
org.junit.runners.ParentRunner.getDescription
3Web pages
1Solution
NoSuchMethodErrorParentRunner.getDescription3
Package namePatterns foundSolution coverageSummary coverage
org.junit.runners1374
org.junit.internal.runners.statements218
junit.framework150
org.junit.internal.requests149
org.junit.runners.model117
org.junit57
org.junit.runner52
org.junit.internal.runners49
org.junit.rules33
junit.extensions30
org.junit.internal.builders24
org.junit.internal.runners.model20
org.junit.runner.notification11
org.junit.internal.runners.rules3
org.junit.experimental.categories3
org.junit.runner.manipulation2
org.junit.internal2
junit.textui2
junit.runner1
org.junit.experimental.theories1
junit.swingui1
Package nameClass namePatterns foundSolution coverageSummary coverage
org.junit.runnersParentRunner1159
org.junit.internal.requestsClassRequest140
org.junit.internal.runners.statementsInvokeMethod135
org.junit.runnersParentRunner$2112
junit.frameworkTestSuite81
org.junit.runners.modelFrameworkMethod62
org.junit.runnersBlockJUnit4ClassRunner60
org.junit.internal.runners.statementsRunBefores55
org.junitAssert51
org.junit.runnerJUnitCore42
junit.frameworkTestCase41
org.junit.runners.modelRunnerBuilder33
junit.extensionsTestSetup30
org.junit.internal.runnersJUnit38ClassRunner18
org.junit.internal.runners.modelReflectiveCallable18
org.junit.runners.modelFrameworkMethod$116
org.junit.runnersParentRunner$315
junit.frameworkAssert15
org.junit.internal.buildersAllDefaultPossibilitiesBuilder14
org.junit.internal.runners.statementsRunAfters13
org.junit.internal.runnersJUnit4ClassRunner12
org.junit.runnersSuite11
org.junit.rulesRunRules10
org.junit.runner.notificationRunNotifier10
org.junit.runnersParentRunner$110
org.junit.internal.requestsFilterRequest9
org.junit.rulesExternalResource$18
org.junit.internal.runners.statementsFailOnTimeout$StatementThread8
junit.frameworkTestResult7
org.junit.runnersParameterized6
org.junitAssume6
org.junit.internal.runners.statementsExpectException6
org.junit.internal.buildersAnnotatedBuilder5
org.junit.runners.modelTestClass5
org.junit.internal.buildersSuiteMethodBuilder5
org.junit.rulesTemporaryFolder4
org.junit.internal.runnersErrorReportingRunner4
org.junit.rulesExpectedException4
org.junit.internal.runnersMethodRoadie4
junit.frameworkTestResult$14
org.junit.rulesTestWatcher$13
org.junit.runnerRunner3
org.junit.experimental.categoriesCategories3
org.junit.internal.runnersMethodValidator3
org.junit.runnerRequest3
junit.textuiTestRunner2
org.junit.rulesExpectedException$ExpectedExceptionStatement2
org.junit.internal.runnersTestClassRunner2
org.junit.internal.runners.rulesRuleFieldValidator2
org.junit.runnerDescription2
Package nameClass nameMethod namePatterns foundSolution coverage
org.junit.runnersParentRunnerrun1106
org.junit.internal.requestsClassRequestgetRunner140
org.junit.internal.runners.statementsInvokeMethodevaluate135
org.junit.runnersParentRunner$2evaluate112
junit.frameworkTestSuiterun76
org.junit.runners.modelFrameworkMethodinvokeExplosively60
org.junit.internal.runners.statementsRunBeforesevaluate55
org.junit.runners.modelRunnerBuildersafeRunnerForClass31
junit.extensionsTestSetuprun30
org.junit.runnerJUnitCorerun27
org.junit.runnersBlockJUnit4ClassRunnerrunChild27
org.junit.runnersBlockJUnit4ClassRunner<init>22
org.junit.internal.runners.modelReflectiveCallablerun18
org.junitAssertassertEquals17
org.junit.internal.runnersJUnit38ClassRunnerrun17
org.junit.runners.modelFrameworkMethod$1runReflectiveCall16
org.junit.runnersParentRunner$3run15
org.junit.internal.buildersAllDefaultPossibilitiesBuilderrunnerForClass14
org.junit.internal.runners.statementsRunAftersevaluate13
org.junit.runnerJUnitCoremain13
org.junit.runnersParentRunnerrunChildren12
junit.frameworkTestCaserun12
junit.frameworkTestCaserunBare11
org.junit.runnersParentRunner$1schedule10
org.junit.runnersParentRunnerrunLeaf10
org.junit.rulesRunRulesevaluate10
org.junit.internal.requestsFilterRequestgetRunner9
org.junit.runnersParentRunneraccess$0009
org.junit.internal.runners.statementsFailOnTimeout$StatementThreadrun8
org.junit.rulesExternalResource$1evaluate8
org.junitAssertassertThat7
org.junit.runnersSuiterunChild6
org.junit.runnersParentRunner<init>6
org.junit.internal.runners.statementsExpectExceptionevaluate6
org.junit.runnersParentRunnervalidate6
org.junit.runner.notificationRunNotifierfireTestStarted5
junit.frameworkTestCaseassertEquals5
org.junit.internal.buildersSuiteMethodBuilderhasSuiteMethod5
org.junit.runners.modelTestClass<init>5
junit.frameworkAssertassertEquals5
org.junit.runnersSuite<init>5
org.junit.internal.runnersJUnit4ClassRunnerrun5
org.junit.internal.runnersErrorReportingRunnergetDescription4
junit.frameworkTestResult$1protect4
org.junit.internal.buildersAnnotatedBuilderbuildRunner4
junit.frameworkTestCaserunTest4
org.junitAssertassertNull4
org.junit.runnersParameterized<init>4
junit.frameworkTestResultrun4
org.junitAssertassertTrue4
Package nameClass nameMethod nameException TypePatterns foundSolution coverage
org.junit.runnersParentRunnerrunAssertionError286
org.junit.runnersParentRunnerrunClassNotFoundException92
org.junit.runnersParentRunnerrunNullPointerException88
org.junit.runnersParentRunnerrunSSLHandshakeException71
org.junit.runnersParentRunnerrunSSLException69
org.junit.runnersParentRunnerrunIllegalArgumentException47
org.junit.internal.runners.statementsInvokeMethodevaluateAssertionError46
org.junit.runnersParentRunnerrunRecordNotFoundException41
org.junit.runnersParentRunnerrunComparisonFailure38
org.junit.runners.modelFrameworkMethodinvokeExplosivelyUnsupportedCallbackException38
org.junit.runnersParentRunnerrunMalformedURLException36
org.junit.runnersParentRunnerrunJSONException29
org.junit.internal.runners.statementsInvokeMethodevaluateNullPointerException28
org.junit.internal.requestsClassRequestgetRunnerException27
org.junit.internal.requestsClassRequestgetRunnerIllegalStateException25
org.junit.internal.requestsClassRequestgetRunnerNoClassDefFoundError24
org.junit.runnersParentRunner$2evaluateIllegalStateException23
junit.frameworkTestSuiterunAssertionFailedError20
org.junit.internal.requestsClassRequestgetRunnerCucumberException20
org.junit.runnersParentRunnerrunRuntimeException20
org.junit.runnersParentRunnerrunIllegalStateException17
org.junit.runnersParentRunnerrunFileNotFoundException17
org.junit.runnersParentRunnerrunArrayIndexOutOfBoundsException16
org.junit.runnersParentRunnerrunClientHandlerException16
org.junit.runnersParentRunnerrunWebServiceException16
org.junit.runnersParentRunnerrunNoClassDefFoundError12
org.junit.internal.requestsClassRequestgetRunnerNoSuchMethodError11
org.junit.internal.runners.statementsRunBeforesevaluateAssertionError11
org.junit.runnersParentRunnerrunSQLException11
org.junit.runnersParentRunner$2evaluateSQLException10
org.junit.runnersBlockJUnit4ClassRunner<init>Exception9
org.junit.runners.modelRunnerBuildersafeRunnerForClassException9
org.junit.runnersParentRunner$2evaluateNoClassDefFoundError8
org.junit.internal.runners.statementsRunBeforesevaluateNullPointerException8
org.junit.internal.runners.statementsInvokeMethodevaluateComparisonFailure8
org.junitAssertassertEqualsAssertionError7
org.junit.runnersParentRunner$2evaluateBeanCreationException7
org.junit.runnersParentRunnerrunMySQLSyntaxErrorException7
org.junit.rulesExternalResource$1evaluateAssertionError7
org.junit.runnersParentRunnerrunServerDeploymentHelper$ServerDeploymentException7
org.junit.runnersParentRunnervalidateException6
org.junit.internal.buildersAllDefaultPossibilitiesBuilderrunnerForClassException6
org.junit.internal.runners.modelReflectiveCallablerunIllegalStateException6
org.junit.runnersBlockJUnit4ClassRunnerrunChildAssertionError6
org.junit.runnersParentRunnerrunIOException6
org.junit.runnersParentRunner$2evaluateMySQLSyntaxErrorException6
org.junitAssertassertEqualsArrayIndexOutOfBoundsException6
org.junit.runnersParentRunner$2evaluateAssertionError5
org.junit.runners.modelRunnerBuildersafeRunnerForClassIllegalArgumentException5
org.junit.internal.requestsFilterRequestgetRunnerException5