Skip to content

Commit

Permalink
Change tests to use JUnitParams
Browse files Browse the repository at this point in the history
Change the unit tests to use the JUnitParams library for more easy testing across the dataset.
  • Loading branch information
ExcaliburZero committed Apr 2, 2016
1 parent 4322079 commit f7ddc6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
}

dependencies {
testCompile "junit:junit:4.12"
testCompile "junit:junit:4.12", "pl.pragmatists:JUnitParams:1.0.4"
}

jacocoTestReport {
Expand Down
42 changes: 26 additions & 16 deletions test/finitestateautomata/EvenZerosMachineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*/
package finitestateautomata;

import junitparams.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;

/**
Expand All @@ -33,27 +35,15 @@
* @see finitestateautomata.EvenZerosMachine
* @author Christopher Wells {@literal <cwellsny@nycap.rr.com>}
*/
@RunWith(JUnitParamsRunner.class)
public class EvenZerosMachineTest {

/**
* Runs tests of the <code>EvenZerosMachine</code> class.
* Tests exception cases of the <code>EvenZerosMachine</code> class.
*/
@Test
public void machineTest() {
EvenZerosMachine testMachine = new EvenZerosMachine("01010101");
assertTrue(testMachine.getResult());

testMachine = new EvenZerosMachine("010101");
assertFalse(testMachine.getResult());

testMachine = new EvenZerosMachine("01010");
assertFalse(testMachine.getResult());

testMachine = new EvenZerosMachine("0");
assertFalse(testMachine.getResult());

testMachine = new EvenZerosMachine("");
assertTrue(testMachine.getResult());
public void testMachineExceptions() {
EvenZerosMachine testMachine;

try {
testMachine = new EvenZerosMachine(null);
Expand All @@ -70,4 +60,24 @@ public void machineTest() {
}
}

/**
* Test several inputs and outputs for the <code>EvenZerosMachine</code>
* class.
*/
@Test
@Parameters({
"0, false",
"01, false",
"001, true",
"01010101, true",
"010101, false",
"001, true",
"1, true",
", true",
})
public void testMachineInput(String input, boolean expectedOutput) {
EvenZerosMachine machine = new EvenZerosMachine(input);
assertEquals(expectedOutput, machine.getResult());
}

}

0 comments on commit f7ddc6d

Please sign in to comment.