Skip to content

Commit

Permalink
refactor(test): combine test classes to parameterized test, with a ma…
Browse files Browse the repository at this point in the history
…ven profile for running backend test (skipped by default).
  • Loading branch information
cmhulbert committed Feb 22, 2024
1 parent d12b257 commit 6a28479
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 755 deletions.
46 changes: 29 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,17 @@
</repositories>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>org.janelia.saalfeldlab.n5.s3.backend.N5AmazonS3BucketRootBackendTest</exclude>
<exclude>org.janelia.saalfeldlab.n5.s3.backend.N5AmazonS3ContainerPathBackendTest</exclude>
<exclude>org.janelia.saalfeldlab.n5.s3.backend.CachedN5AmazonS3BucketRootBackendTest</exclude>
<exclude>org.janelia.saalfeldlab.n5.s3.backend.CachedN5AmazonS3ContainerPathBackendTest</exclude>
<exclude>org.janelia.saalfeldlab.n5.s3.backend.BackendUriTest</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>org.janelia.saalfeldlab.n5.s3.backend.*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
Expand All @@ -201,5 +195,23 @@
<maven.compiler.release>${scijava.jvm.version}</maven.compiler.release>
</properties>
</profile>
<profile>
<id>run-backend-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<propertyName>run-backend-tests</propertyName>
<value>true</value>
</systemPropertyVariables>
<excludes combine.self="override"/>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.janelia.saalfeldlab.n5.s3;

import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.Filterable;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runners.model.InitializationError;
import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory;
import org.junit.runners.parameterized.TestWithParameters;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Objects;

public class IgnoreTestCasesByParameter extends BlockJUnit4ClassRunnerWithParametersFactory {

private static Filter skipAll = new Filter() {

@Override public boolean shouldRun(Description description) {

return false;
}

@Override public String describe() {

return "Backend Tests Not Enabled";
}
};
@Override public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError {

final IgnoreParameter annotation = test.getTestClass().getAnnotation(IgnoreParameter.class);
final int ignoreIndex = annotation != null ? annotation.index() : -1;
final int idx = ignoreIndex == -1 ? test.getParameters().size() - 1 : ignoreIndex;

final Object ignoreTests = test.getParameters().get(idx);
final Runner runnerForTestWithParameters = super.createRunnerForTestWithParameters(test);
if (Objects.equals(ignoreTests, true)) {
if (runnerForTestWithParameters instanceof Filterable) {
try {
((Filterable)runnerForTestWithParameters).filter(skipAll);
} catch (NoTestsRemainException ignored) {
}
}
};
return runnerForTestWithParameters;
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface IgnoreParameter {
/**
* Optional index to specify where the boolean that is used to determine
* whether a ParameterizedTest run is skipped or not.
*
* Default value is -1, which uses the final index of the paremeter list.
*
* @return index to query for whether to ignore the test cases or not.
*/
int index() default -1;
}
}
Loading

0 comments on commit 6a28479

Please sign in to comment.