Note that there are some explanatory texts on larger screens.

plurals
  1. POJUnit @Theory : is there a way to throw meaningful exception?
    primarykey
    data
    text
    <p>I tried Junit @Theory test style recently : it's a really efficient way of testing. However, i not pleased with the exception that are thrown when a test fails. Example :</p> <pre><code>import static org.junit.Assert.assertEquals; import org.junit.experimental.theories.DataPoint; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; @RunWith(Theories.class) public class TheoryAndExceptionTest { @DataPoint public static String yesDataPoint = "yes"; @Theory public void sayNo(final String say) { assertEquals("no",say); } } </code></pre> <p>I expect this test to throw a <strong>descriptive</strong> exception, but instead of getting something like :</p> <pre><code>org.junit.ComparisonFailure: expected:&lt;'[no]'&gt; but was:&lt;'[yes]'&gt; </code></pre> <p>... I get this :</p> <pre><code>org.junit.experimental.theories.internal.ParameterizedAssertionError: sayNo(yes) at .... [23 lines of useless stack trace cut] ... Caused by: org.junit.ComparisonFailure: expected:&lt;'[no]'&gt; but was:&lt;'[yes]'&gt; .... </code></pre> <p>Is there a way to get rid of the 24 first lines that tell nothing about *<em>my</em>*test, except that yesDataPoint @DataPoint causes the failure ? That's an information i need, to know what is failing, but i really would like to know <em>how</em> it fails on the same time.</p> <p><strong>[edited]</strong></p> <p>I replaced org.fest.assertions usage by classic org.junit.Assert.assertEquals, to avoid confusion. Additionally, it's not related either with Eclipse : that long (useless/confusing) stack trace is what you get too when you run and fail a @Theory from the command line.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload