mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Support @Skip on test classes and methods
Add super class for all test types (method, scenario, end-to-end), and an class & method level annotation for skipping tests.
This commit is contained in:
parent
390cba1b75
commit
96cabfb177
2 changed files with 119 additions and 0 deletions
81
apitest/src/main/java/bisq/apitest/ApiTestCase.java
Normal file
81
apitest/src/main/java/bisq/apitest/ApiTestCase.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.apitest;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
|
||||
|
||||
import bisq.apitest.annotation.Skip;
|
||||
|
||||
public class ApiTestCase {
|
||||
|
||||
protected static final char CHECK = '\u2714';
|
||||
protected static final char CROSS_MARK = '\u274c';
|
||||
|
||||
public int countTestCases;
|
||||
public int countFailedTestCases;
|
||||
public int countSkippedTestCases;
|
||||
public int countPassedTestCases;
|
||||
|
||||
private final Predicate<Class<?>> skipAll = (c) -> c.getAnnotation(Skip.class) != null;
|
||||
private final Predicate<Method> skip = (m) -> m.getAnnotation(Skip.class) != null;
|
||||
|
||||
protected boolean isSkipped(String methodName) {
|
||||
try {
|
||||
if (skipAll.test(this.getClass()) || skip.test(getMethod(methodName))) {
|
||||
countSkippedTestCases++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
countTestCases++; // Increment the test case count, skipped or not.
|
||||
}
|
||||
}
|
||||
|
||||
protected Method getMethod(String methodName) {
|
||||
try {
|
||||
return this.getClass().getMethod(methodName);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new IllegalStateException(format("No method '%s' exists in class '%s'",
|
||||
methodName, this.getClass().getName()),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected String reportString() {
|
||||
return format("Total %d Passed %d Failed %d Skipped %d",
|
||||
countTestCases,
|
||||
countPassedTestCases,
|
||||
countFailedTestCases,
|
||||
countSkippedTestCases);
|
||||
}
|
||||
|
||||
protected void sleep(long ms) {
|
||||
try {
|
||||
MILLISECONDS.sleep(ms);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
38
apitest/src/main/java/bisq/apitest/annotation/Skip.java
Normal file
38
apitest/src/main/java/bisq/apitest/annotation/Skip.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.apitest.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Sometimes you want to temporarily disable a test or a group of tests. Methods that
|
||||
* are annotated with <code>@Skip</code> will not be executed as tests.
|
||||
* Also, you can annotate a class containing test methods with <code>@Skip</code>
|
||||
* and none of the containing tests will be executed.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
public @interface Skip {
|
||||
/**
|
||||
* The optional reason why the test is skipped.
|
||||
*/
|
||||
String value() default "";
|
||||
}
|
Loading…
Add table
Reference in a new issue