mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Add JUnitHelper to run tests from JUnitCore
This commit is contained in:
parent
687bcf1d8f
commit
2852e3da8b
3 changed files with 77 additions and 43 deletions
51
apitest/src/main/java/bisq/apitest/JUnitHelper.java
Normal file
51
apitest/src/main/java/bisq/apitest/JUnitHelper.java
Normal file
|
@ -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())));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue