Class TestFailure


  • @Incubating
    public abstract class TestFailure
    extends java.lang.Object
    Describes a test failure. Contains a reference to the failure and some structural information retrieved by the test worker.
    Since:
    7.6
    • Constructor Detail

      • TestFailure

        public TestFailure()
    • Method Detail

      • getCauses

        public abstract java.util.List<TestFailure> getCauses()
        Returns the list of causes.

        The result is typically non-empty for multi-assertion failures, e.g. for org.test4j.MultipleFailuresError, where the individual failures are in the returned list.

        Returns:
        the cause failures.
      • getRawFailure

        public abstract java.lang.Throwable getRawFailure()
        Returns the raw failure.
        Returns:
        the raw failure
      • getDetails

        public abstract TestFailureDetails getDetails()
        Returns structural information about the failure.
        Returns:
        the failure structure
      • fromTestAssertionFailure

        public static TestFailure fromTestAssertionFailure​(java.lang.Throwable failure,
                                                           java.lang.String expected,
                                                           java.lang.String actual)
        Creates a new TestFailure instance from an assertion failure.
        Parameters:
        failure - the assertion failure
        expected - the expected value for the failure; can be null
        actual - the actual value for the failure; can be null
        Returns:
        the new instance
      • fromTestAssertionFailure

        public static TestFailure fromTestAssertionFailure​(java.lang.Throwable failure,
                                                           java.lang.String expected,
                                                           java.lang.String actual,
                                                           java.util.List<TestFailure> causes)
        Creates a new TestFailure instance from an assertion failure.
        Parameters:
        failure - the assertion failure
        expected - the expected value for the failure; can be null
        actual - the actual value for the failure; can be null
        causes - the list of cause failures; can be null
        Returns:
        the new instance
      • fromFileComparisonFailure

        public static TestFailure fromFileComparisonFailure​(java.lang.Throwable failure,
                                                            java.lang.String expected,
                                                            java.lang.String actual,
                                                            byte[] expectedContent,
                                                            byte[] actualContent,
                                                            java.util.List<TestFailure> causes)
        Todo
        Since:
        8.3
      • fromTestFrameworkFailure

        public static TestFailure fromTestFrameworkFailure​(java.lang.Throwable failure)
        Creates a new TestFailure instance from a test framework failure.
        Parameters:
        failure - the failure
        Returns:
        the new instance
      • fromTestFrameworkFailure

        public static TestFailure fromTestFrameworkFailure​(java.lang.Throwable failure,
                                                           java.util.List<TestFailure> causes)
        Creates a new TestFailure instance from a test framework failure.
        Parameters:
        failure - the failure
        causes - the list of cause failures; can be null
        Returns:
        the new instance