Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think, you can make it with the new feautures of JUnit4.</p> <p>Write a Rule that executes @Before and @After each time: <a href="http://weblogs.java.net/blog/johnsmart/archive/2010/09/30/junit-kung-fu-getting-more-out-your-unit-tests" rel="nofollow">JUnit Kungfu slide 34</a></p> <p>Write a Parameterized Test that calculates the result: <a href="http://weblogs.java.net/blog/johnsmart/archive/2010/09/30/junit-kung-fu-getting-more-out-your-unit-tests" rel="nofollow">JUnit Kungfu slide 23</a></p> <p>If you work with spreadsheet you can fill your spreadsheet with values like current-value;expected-min;expected-max</p> <pre><code>import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; import static org.junit.matchers.JUnitMatchers.*; import java.util.Arrays; import java.util.Collection; import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class ParameterizedTest { private final int min; private final int max; private final int current; @Parameters public static Collection&lt;Object[]&gt; data() { return Arrays.asList(new Object[][] { { -1 , -10, -6 }, { -2 , -11, -7 }, { -3 , -12, -8 }, { -4 , -13, -9 }, { -5 , -14, -10 } }); } public ParameterizedTest(int current, int expectedMin, int expectedMax) { this.current = current; this.min = expectedMin; this.max = expectedMax; } @Test public void testName() throws Exception { int yourNewValue = YourNormalizer.normalize(current); assertThat(yourNewValue, both(greaterThan(min)).and(lessThanOrEqualTo(max))); } } </code></pre> <p>I don't know any other way to test data. HF</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.
    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