I have custom Interface "Platform" with @ExtendWith annotation and Class which implements ExecutionCondition.
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@ExtendWith(PlatformExecutionCondition.class)
public @interface Platform {
MobilePlatform[] value();
@Component
@RequiredArgsConstructor
public class PlatformExecutionCondition implements ExecutionCondition {
private final EmulatorConfigProperties emulatorConfigProperties;
private final PlatformAnnotationManager platformAnnotationManager;
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
MobilePlatform platform = MobilePlatform.getByName(emulatorConfigProperties.getPlatformName());
if (platform == null) {
return disabled("Mobile platform is not specified");
}
if (extensionContext.getTestMethod().isEmpty()) {
return enabled("Test class execution enabled");
}
Set<MobilePlatform> mobilePlatforms = platformAnnotationManager.getTestMobilePlatforms(extensionContext);
if (mobilePlatforms.contains(platform)) {
return enabled(format("{0} mobile platform is available for testing", platform.getName()));
} else {
return disabled(format("{0} mobile platform is not available for testing", platform.getName()));
}
}
}
While running the test, I catch an error java.lang.NoSuchMethodException: com.mob.market3b.platform.execution.PlatformExecutionCondition.<init>() If I remove the annotation, the test runs without errors, but then the evaluateExecutionCondition method is not in use. How can I use @ExtendWith annotation with Spring?
@ExtendWith. SeeExtensionfor details. The@RequiredArgsConstructorannotation on your class means you don't have a no-argument constructor. Are you asking how to inject dependencies into a JUnit extension?