I'd like to add some custom assertions to our code base that properly hide from the failure trace. I know how to write a public static method that someone can statically import. I know how to reuse old assertions or throw a new AssertionError
.
What I can't figure out how to do is keep the new custom assertions out of the Failure Trace. We're used to the first hit in the failure trace NOT being the assertion code itself but the test code that called the assertion.
I know there is a filtertrace
attribute that controls filtering the stack but I can't find any good documentation of what I'd have to do to add the new assertions to the filter.
An example of what I want to do:
package testassertions;
import static newassertions.MyAssertions.myAssertTrue;
import org.junit.Test;
public class ExampleTest {
@Test
public void myAssertTruePassing() { myAssertTrue(true); }
@Test
public void myAssertTrueFailing() { myAssertTrue(false); }
}
package newassertions;
import static org.junit.Assert.assertTrue;
public class MyAssertions {
public static void myAssertTrue(boolean b) {
assertTrue(b);
}
}
Failure Trace of myAssertTrueFailing() shows:
java.lang.AssertionError
at newassertions.MyAssertions.myAssertTrue(MyAssertions.java:8)
at testassertions.ExampleTest.myAssertTrueFailing(ExampleTest.java:12)
I need it to only show:
java.lang.AssertionError
at testassertions.ExampleTest.myAssertTrueFailing(ExampleTest.java:12)