The following is a trick I don’t use very often, but when I do need it, it comes in very handy. It’s a trick that many developers aren’t aware of, even though it’s been possible to do with JUnit at least since version 3.Sometimes you want to have a lot of tests that are almost the same, but that contain different arguments. For example, for a yahtzee calculator, you might want to have the following tests:checkRollScoredAsCategoryGives<span style="color: #009900;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #0000ff;">"straight"</span>, <span style="color: #cc66cc;">15</span><span style="color: #009900;">)</span>; checkRollScoredAsCategoryGives<span style="color: #009900;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"straight"</span>, 0<span style="color: #009900;">)</span>; checkRollScoredAsCategoryGives<span style="color: #009900;">(</span><span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"full house"</span>, <span style="color: #cc66cc;">17</span><span style="color: #009900;">)</span>; checkRollScoredAsCategoryGives<span style="color: #009900;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"full house"</span>, 0<span style="color: #009900;">)</span>; checkRollScoredAsCategoryGives<span style="color: #009900;">(</span><span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"full house"</span>, 0<span style="color: #009900;">)</span>;This is possible with JUnit, but a little trick. You have to construct a test suite manually and add special subclasses of TestCase to it: <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Test suite<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span> TestSuite suite <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TestSuite<span style="color: #009900;">(</span> YahtzeeScoreTest.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span>; suite.<span style="color: #006633;">addTest</span><span style="color: #009900;">(</span>checkRollScoredAsCategoryGives<span style="color: #009900;">(</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #0000ff;">"small straight"</span>, <span style="color: #cc66cc;">15</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span>; suite.<span style="color: #006633;">addTest</span><span style="color: #009900;">(</span>checkRollScoredAsCategoryGives<span style="color: #009900;">(</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"small straight"</span>, 0<span style="color: #009900;">)</span><span style="color: #009900;">)</span>; suite.<span style="color: #006633;">addTest</span><span style="color: #009900;">(</span>checkRollScoredAsCategoryGives<span style="color: #009900;">(</span> <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"full house"</span>, <span style="color: #cc66cc;">17</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span>; suite.<span style="color: #006633;">addTest</span><span style="color: #009900;">(</span>checkRollScoredAsCategoryGives<span style="color: #009900;">(</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"full house"</span>, 0<span style="color: #009900;">)</span><span style="color: #009900;">)</span>; suite.<span style="color: #006633;">addTest</span><span style="color: #009900;">(</span>checkRollScoredAsCategoryGives<span style="color: #009900;">(</span> <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #0000ff;">"full house"</span>, 0<span style="color: #009900;">)</span><span style="color: #009900;">)</span>; <span style="color: #000000; font-weight: bold;">return</span> suite; <span style="color: #009900;">}</span> <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Test checkRollScoredAsCategoryGives<span style="color: #009900;">(</span> <span style="color: #000066; font-weight: bold;">int</span> die1, <span style="color: #000066; font-weight: bold;">int</span> die2, <span style="color: #000066; font-weight: bold;">int</span> die3, <span style="color: #000066; font-weight: bold;">int</span> die4, <span style="color: #000066; font-weight: bold;">int</span> die5, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> category, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> expectedResult<span style="color: #009900;">)</span> <span style="color: #009900;">{</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">[</span><span style="color: #009900;">]</span> dice <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">[</span><span style="color: #009900;">]</span> <span style="color: #009900;">{</span> die1, die2, die3, die4, die5 <span style="color: #009900;">}</span>; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> TestCase<span style="color: #009900;">(</span><span style="color: #0000ff;">"Rolling for "</span> <span style="color: #339933;">+</span> category<span style="color: #009900;">)</span> <span style="color: #009900;">{</span> @Override <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> runTest<span style="color: #009900;">(</span><span style="color: #009900;">)</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Throwable</span> <span style="color: #009900;">{</span> YahtzeeScoreboard board <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> YahtzeeScoreboard<span style="color: #009900;">(</span><span style="color: #009900;">)</span>; board.<span style="color: #006633;">scoreRoll</span><span style="color: #009900;">(</span>category, dice<span style="color: #009900;">)</span>; assertEquals<span style="color: #009900;">(</span>expectedResult, board.<span style="color: #006633;">getTotalScore</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span>; <span style="color: #009900;">}</span> <span style="color: #009900;">}</span>; <span style="color: #009900;">}</span>The code creates an anonymous inner subclass of TestCase that instead of calling all methods annotated with @Test just executes our specific test. These tests are collected in a normal JUnit TestSuite.The test is plain JUnit and will run in Maven or your favorite IDE, just as any other tests. The fact that the suite is named after the test class will let Eclipse know where to go when you double click on the test from the test runner.This trick can be very useful for tests of logic that calculates a results or validates input. Java