I get this error:
/student/src/reflection/tester/TestRunnerTests.java:21: error: unreported exception Exception; must be caught or declared to be thrown testRunner.runTests(testClassNames);
So it shows that the error must be on testRunner.runTests(testClassNames);
line in this class:
public class TestRunnerTests {
@Test
public void runsTestsFromDecoupledFiles() throws Exception {
List<String> testClassNames = List.of(
"reflection.tester.ExampleTests1", "reflection.tester.ExampleTests2");
TestRunner testRunner = new TestRunner();
testRunner.runTests(testClassNames);
String result = testRunner.getResult();
assertThat(result, containsString("test1() - OK"));
assertThat(result, containsString("test2() - FAILED"));
assertThat(result, containsString("test3() - OK"));
assertThat(result, containsString("test4() - FAILED"));
assertThat(result, containsString("test5() - OK"));
assertThat(result, containsString("test6() - FAILED"));
assertThat(result, not(containsString("helperMethod()")));
}
}
My actual code looks like this:
public class TestRunner{
List<String> result = new LinkedList<>();
List<String> annotatedMethods = new LinkedList<>();
public void runTests(List<String> testClassNames) throws Exception {
for (String test: testClassNames) {
Class<?> aClass = Class.forName(test);
getClassMethods(aClass);
}
}
.....
}
Tried something like this, but it says A catch statement that catches an exception only to wrap it in a new instance of the same type of exception and throw it should be avoided
try{
for (String test: testClassNames) {
Class<?> aClass = Class.forName(test);
getClassMethods(aClass);
}
} catch (Exception e){
throw new Exception(e);
}
How should I solve it?