Pattern selector

Most relevant patterns first. Most helpful ones displayed. Click here to show all.

  1. Assert.assertTrue() has thrown an AssertionFailedError
    JUnit
    10
    38
    14
  2. JUnit fail method
    JUnit
    94
    252
    97

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
junit.framework.AssertionFailedError
    at junit.framework.Assert.fail(Assert.java:48)
    at junit.framework.Assert.assertTrue(Assert.java:20)
    at junit.framework.Assert.assertTrue(Assert.java:27)
    at android.permission.cts.FileSystemPermissionTest.testRunAsHasCorrectCapabilities(FileSystemPermissionTest.java:828)
12 frames hidden

Solution

JaviRpo2 months ago

AssertionFailedError 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 shouldAssertStrings() { 
      ...
      if( ... ) {
         fail("Any message");
      }
   } 
}

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

External results for this pattern (10)

  1. Dawid Loubservia Google Groups1 week ago
    expected:<1> but was:<0>
    Show stack trace
  2. Dawid Loubservia Google Groups1 week ago
    null
    Show stack trace
  3. El Deffovia Google Groups1 week ago
    null
    Show stack trace
  4. Maxime Gréauvia JIRA1 week ago
    Expected: <null> but was: file:/srv/ciagent/workspace/target/test-classes/repo/MyClass.groovy
    Show stack trace
  5. Franz Willervia JIRA1 week ago
    Created Document not found! uid:create.test.1.3
    Show stack trace
  6. shinsuke-matvia GitHub2 weeks ago
    Expecting IllegalArgumentException - non-bracketing
    Show stack trace
  7. No message found for this stack trace.
    Show stack trace
  8. aarthipavia GitHub1 month ago
    expected:<982007015> but was:<1232306490>
    Show stack trace
  9. lewismcvia GitHub2 months ago
    Validation of file succeeded when it should have failed expected:<false> but was:<true>
    Show stack trace
  10. vijjusreevia GitHub2 months ago
    Query result size expected:<2> but was:<1>
    Show stack trace