use of org.kanonizo.framework.objects.ParameterisedTestCase in project kanonizo by kanonizo.
the class Framework method loadClasses.
public void loadClasses() throws ClassNotFoundException {
sut = new SystemUnderTest();
List<File> sourceFiles = findClasses(sourceFolder);
Premain.instrument = true;
for (File file : sourceFiles) {
Class<?> cl = loadClassFromFile(file);
sut.addClass(new ClassUnderTest(cl));
logger.info("Added class " + cl.getName());
}
Premain.instrument = false;
List<File> testFiles = findClasses(testFolder);
for (File file : testFiles) {
Class<?> cl = loadClassFromFile(file);
if (cl != null) {
if (Util.isTestClass(cl)) {
List<Method> testMethods = TestingUtils.getTestMethods(cl);
logger.info("Adding " + testMethods.size() + " test methods from " + cl.getName());
for (Method m : testMethods) {
if (TestingUtils.isParameterizedTest(cl, m)) {
Optional<Method> parameterMethod = Arrays.asList(cl.getMethods()).stream().filter(method -> method.getAnnotation(Parameters.class) != null).findFirst();
if (parameterMethod.isPresent()) {
try {
Iterable<Object[]> parameters = (Iterable<Object[]>) parameterMethod.get().invoke(null, new Object[] {});
for (Object[] inst : parameters) {
ParameterisedTestCase ptc = new ParameterisedTestCase(cl, m, inst);
sut.addTestCase(ptc);
}
} catch (IllegalAccessException e) {
logger.error(e);
} catch (InvocationTargetException e) {
logger.error(e);
}
} else {
logger.error("Trying to create parameterized test case that has no parameter method");
}
} else {
TestCase t = new TestCase(cl, m);
sut.addTestCase(t);
}
}
} else {
sut.addExtraClass(cl);
logger.info("Adding supporting test class " + cl.getName());
}
}
}
ClassUnderTest.resetCount();
logger.info("Finished adding source and test files. Total " + sut.getClassesUnderTest().size() + " classes and " + sut.getTestSuite().size() + " test cases");
}
use of org.kanonizo.framework.objects.ParameterisedTestCase in project kanonizo by kanonizo.
the class JUnit4TestRunner method getRequest.
private Request getRequest(TestCase tc) {
Class<?> testClass = tc.getTestClass();
Method testMethod = tc.getMethod();
try {
final RunWith runWith = testClass.getAnnotation(RunWith.class);
if (runWith != null) {
final Class<? extends Runner> runnerClass = runWith.value();
if (runnerClass.isAssignableFrom(Parameterized.class)) {
try {
if (tc instanceof ParameterisedTestCase) {
ParameterisedTestCase ptc = (ParameterisedTestCase) tc;
Class.forName(// ignore IgnoreIgnored for junit4.4 and <
"org.junit.runners.BlockJUnit4ClassRunner");
return Request.runner(new ParameterizedMethodRunner(testClass, testMethod.getName(), ptc.getParameters()));
}
} catch (Throwable thrown) {
logger.error(thrown);
}
}
} else {
if (testMethod != null && testMethod.getAnnotation(Ignore.class) != null) {
// override ignored case only
final Request classRequest = new ClassRequest(testClass) {
public Runner getRunner() {
try {
return new IgnoreIgnoredTestJUnit4ClassRunner(testClass);
} catch (Exception ignored) {
}
return super.getRunner();
}
};
return classRequest.filterWith(Description.createTestDescription(testClass, testMethod.getName()));
}
}
} catch (Exception ignored) {
logger.error(ignored);
}
return Request.method(testClass, testMethod.getName());
}
Aggregations