Last active
August 29, 2015 14:00
-
-
Save wytten/11266597 to your computer and use it in GitHub Desktop.
Locate all the groovy scripts in a certain package within the classpath, and execute them as a JUnit 4.x test suite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(Parameterized.class) | |
public class GroovySystemTest { | |
@Parameters(name = "{0}") | |
public static Collection<Object[]> data() throws Exception { | |
Collection<Object[]> data = new ArrayList<Object[]>(); | |
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); | |
provider.addIncludeFilter(new AssignableTypeFilter(Script.class)); | |
Set<BeanDefinition> components = provider.findCandidateComponents("package.of.interest"); | |
LOG.debug("set size=" + components.size()); | |
for (BeanDefinition component : components) { | |
@SuppressWarnings("unchecked") | |
Class<Script> cls = (Class<Script>) Class.forName(component.getBeanClassName()); | |
Script script = cls.newInstance(); | |
script.setBinding(new Binding(new String[0])); | |
data.add(new Object[] { script }); | |
} | |
LOG.debug("data size=" + data.size()); | |
return data; | |
} | |
@Test | |
public void test() { | |
final String name = script.getClass().getName(); | |
LOG.info("Running {}", name); | |
script.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment