Skip to content

Commit 69c1798

Browse files
committed
Build out java_test_run to handle test suites
1 parent 459136a commit 69c1798

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package codecademy.intermediate_course;
2+
3+
import org.junit.runner.JUnitCore;
4+
import org.junit.runner.Result;
5+
import org.junit.runner.notification.Failure;
6+
7+
public class FactorialTestRunner {
8+
public static void main(String[] args) {
9+
Result result = JUnitCore.runClasses(FactorialTestSuite.class);
10+
11+
for (Failure failure : result.getFailures()) {
12+
System.out.println(failure.toString());
13+
}
14+
15+
System.out.println(result.wasSuccessful());
16+
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package codecademy.intermediate_course;
2+
3+
import org.junit.runner.RunWith;
4+
import org.junit.runners.Suite;
5+
import org.junit.runners.Suite.SuiteClasses;
6+
7+
@RunWith(Suite.class)
8+
@Suite.SuiteClasses({
9+
// List of test classes to bundle togethe
10+
TestFactorial.class
11+
})
12+
13+
// No content needed - just a dummy prop for the test runner
14+
public class FactorialTestSuite {
15+
16+
}

codecademy/intermediate_course/TestFactorial.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package codecademy.intermediate_course;
22

33
import org.junit.Test;
4+
// NOTE: 'static' imports allow pulling static methods from classes
45
import static org.junit.Assert.*;
56

67
public class TestFactorial {

java_test_run.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ if [ $# -ne 1 ]; then
77
fi
88

99
# Set up environment
10-
JAVA_TESTSUITE="$1"
10+
JAVA_TESTCASE="$1"
1111
JAVA_CODE_DIR="$(pwd)/codecademy/intermediate_course"
1212
export JUNIT4_CLASSPATH="/usr/share/java/junit-4.13.2.jar:/usr/share/java/hamcrest-core.jar"
1313

1414
# Run test cases
15-
javac -cp ./:${JUNIT4_CLASSPATH} ${JAVA_CODE_DIR}/${JAVA_TESTSUITE}.java ${JAVA_CODE_DIR}/Factorial.java
16-
java -cp ./:${JUNIT4_CLASSPATH} org.junit.runner.JUnitCore codecademy.intermediate_course.${JAVA_TESTSUITE}
15+
pushd $JAVA_CODE_DIR
16+
javac -cp ./:${JUNIT4_CLASSPATH} \
17+
${JAVA_TESTCASE}.java \
18+
Test${JAVA_TESTCASE}.java \
19+
${JAVA_TESTCASE}TestSuite.java \
20+
${JAVA_TESTCASE}TestRunner.java
21+
popd
22+
java -cp ./:${JUNIT4_CLASSPATH} org.junit.runner.JUnitCore codecademy.intermediate_course.${JAVA_TESTCASE}TestSuite

0 commit comments

Comments
 (0)