下面列出了org.junit.jupiter.api.extension.ExtensionContext#getTestClass() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void beforeEach(ExtensionContext context) throws Exception {
if (assertException != null) {
// Build failed as expected - test methods are not invoked
return;
}
if (runningQuarkusApplication != null) {
runningQuarkusApplication.getClassLoader().loadClass(RestAssuredURLManager.class.getName())
.getDeclaredMethod("setURL", boolean.class).invoke(null, useSecureConnection);
} else {
Optional<Class<?>> testClass = context.getTestClass();
if (testClass.isPresent()) {
Field extensionField = Arrays.stream(testClass.get().getDeclaredFields()).filter(
f -> f.isAnnotationPresent(RegisterExtension.class) && QuarkusUnitTest.class.equals(f.getType()))
.findAny().orElse(null);
if (extensionField != null && !Modifier.isStatic(extensionField.getModifiers())) {
throw new IllegalStateException(
"Test application not started - QuarkusUnitTest must be used with a static field: "
+ extensionField);
}
}
throw new IllegalStateException("Test application not started for an unknown reason");
}
}
public static String getOutputFolder(ExtensionContext context,
String outputFolder) {
if (context == null) {
return "";
}
Optional<Method> testMethod = context.getTestMethod();
Optional<Class<?>> testInstance = context.getTestClass();
if (testMethod.isPresent() && testInstance.isPresent()) {
if (outputFolder.equalsIgnoreCase("surefire-reports")) {
outputFolder = getSurefireOutputFolder(testInstance.get());
} else if (outputFolder.isEmpty()) {
outputFolder = ".";
}
}
log.trace("Output folder {}", outputFolder);
File outputFolderFile = new File(outputFolder);
if (!outputFolderFile.exists()) {
outputFolderFile.mkdirs();
}
return outputFolder;
}