diff --git a/apitest/src/main/java/bisq/apitest/JUnitHelper.java b/apitest/src/main/java/bisq/apitest/JUnitHelper.java new file mode 100644 index 0000000000..affb127b13 --- /dev/null +++ b/apitest/src/main/java/bisq/apitest/JUnitHelper.java @@ -0,0 +1,51 @@ +package bisq.apitest; + +import lombok.extern.slf4j.Slf4j; + +import org.junit.runner.Description; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; + +import static java.lang.String.format; + +@Slf4j +public class JUnitHelper { + + public static void runTests(Class... testClasses) { + JUnitCore jUnitCore = new JUnitCore(); + jUnitCore.addListener(new RunListener() { + public void testStarted(Description description) { + log.info("{}", description); + } + + public void testIgnored(Description description) { + log.info("Ignored {}", description); + } + + public void testFailure(Failure failure) { + log.error("Failed {}", failure.getTrace()); + } + }); + Result result = jUnitCore.run(testClasses); + printTestResults(result); + } + + public static void printTestResults(Result result) { + log.info("Total tests: {}, Failed: {}, Ignored: {}", + result.getRunCount(), + result.getFailureCount(), + result.getIgnoreCount()); + + if (result.wasSuccessful()) { + log.info("All {} tests passed", result.getRunCount()); + } else if (result.getFailureCount() > 0) { + log.error("{} test(s) failed", result.getFailureCount()); + result.getFailures().iterator().forEachRemaining(f -> log.error(format("%s.%s()%n\t%s", + f.getDescription().getTestClass().getName(), + f.getDescription().getMethodName(), + f.getTrace()))); + } + } +} diff --git a/apitest/src/main/java/bisq/apitest/method/MethodTestMain.java b/apitest/src/main/java/bisq/apitest/method/MethodTestMain.java index 504520b633..3840e1c939 100644 --- a/apitest/src/main/java/bisq/apitest/method/MethodTestMain.java +++ b/apitest/src/main/java/bisq/apitest/method/MethodTestMain.java @@ -2,19 +2,13 @@ package bisq.apitest.method; import lombok.extern.slf4j.Slf4j; -import org.junit.runner.Description; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; -import org.junit.runner.notification.Failure; -import org.junit.runner.notification.RunListener; - -import static java.lang.String.format; +import static bisq.apitest.JUnitHelper.runTests; /** * Driver for running API method tests. * * This may not seem necessary, but test cases are contained in the apitest sub - * project's main sources, not its test sources. An IDE will not automatically configure + * project's main sources, not its test sources. An IDE may not automatically configure * JUnit test launchers, and a gradle build will not automatically run the test cases. * * However, it is easy to manually configure an IDE launcher to run all, some or one @@ -24,40 +18,6 @@ import static java.lang.String.format; public class MethodTestMain { public static void main(String[] args) { - JUnitCore jUnitCore = new JUnitCore(); - jUnitCore.addListener(new RunListener() { - public void testStarted(Description description) { - log.info("{}", description); - } - - public void testIgnored(Description description) { - log.info("Ignored {}", description); - } - - public void testFailure(Failure failure) { - log.error("Failed {}", failure.getTrace()); - } - }); - Result result = jUnitCore.run(GetVersionTest.class, GetBalanceTest.class, WalletProtectionTest.class); - ResultUtil.printResult(result); - } - - private static class ResultUtil { - public static void printResult(Result result) { - log.info("Total tests: {}, Failed: {}, Ignored: {}", - result.getRunCount(), - result.getFailureCount(), - result.getIgnoreCount()); - - if (result.wasSuccessful()) { - log.info("All tests passed"); - } else if (result.getFailureCount() > 0) { - log.error("{} test(s) failed", result.getFailureCount()); - result.getFailures().iterator().forEachRemaining(f -> log.error(format("%s.%s()%n\t%s", - f.getDescription().getTestClass().getName(), - f.getDescription().getMethodName(), - f.getTrace()))); - } - } + runTests(GetVersionTest.class, GetBalanceTest.class, WalletProtectionTest.class); } } diff --git a/apitest/src/main/java/bisq/apitest/scenario/ScenarioTestMain.java b/apitest/src/main/java/bisq/apitest/scenario/ScenarioTestMain.java new file mode 100644 index 0000000000..0fb115939a --- /dev/null +++ b/apitest/src/main/java/bisq/apitest/scenario/ScenarioTestMain.java @@ -0,0 +1,23 @@ +package bisq.apitest.scenario; + +import lombok.extern.slf4j.Slf4j; + +import static bisq.apitest.JUnitHelper.runTests; + +/** + * Driver for running API scenario tests. + * + * This may not seem necessary, but test cases are contained in the apitest sub + * project's main sources, not its test sources. An IDE may not automatically configure + * JUnit test launchers, and a gradle build will not automatically run the test cases. + * + * However, it is easy to manually configure an IDE launcher to run all, some or one + * JUnit test, and new gradle tasks should be provided to run all, some, or one test. + */ +@Slf4j +public class ScenarioTestMain { + + public static void main(String[] args) { + runTests(FundWalletScenarioTest.class); + } +}