@Override public TestResult execute(Class<?> testClass, String methodName) { ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); try { // Make sure we run in the context of the arquillian-bundle class loader Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); return super.execute(testClass, methodName); } finally { Thread.currentThread().setContextClassLoader(ctxLoader); } } }
@Test public void shouldReturnExceptionOnPassedTest() throws Exception { // Simulate setting the Exception like Arquillian would. This is a JUnit hack to avoid JUnit Swallowing the Exception. Arquillian.caughtTestException.set(new IllegalArgumentException()); JUnitTestRunner runner = new JUnitTestRunner(); TestResult result = runner.execute(JUnitTestRunnerTestCase.class, "shouldProvideExpectedExceptionToRunner"); Assert.assertNotNull(result); Assert.assertEquals(TestResult.Status.PASSED, result.getStatus()); Assert.assertNotNull(result.getThrowable()); Assert.assertEquals(IllegalArgumentException.class, result.getThrowable().getClass()); }
public TestResult execute(Class<?> testClass, String methodName) { DeployableTestBuilder.setProfile(getProfile()); JUnitCore runner = new JUnitCore(); ExpectedExceptionHolder exceptionHolder = new ExpectedExceptionHolder(); runner.addListener(exceptionHolder); for (RunListener listener : getRunListeners()) runner.addListener(listener); Result result = runner.run(Request.method(testClass, methodName)); DeployableTestBuilder.clearProfile(); return convertToTestResult(result, exceptionHolder.getException()); }
@Test public void shouldReturnPassedTest() throws Exception { JUnitTestRunner runner = new JUnitTestRunner(); TestResult result = runner.execute(JUnitTestRunnerTestCase.class, "shouldProvidePassingTestToRunner"); Assert.assertNotNull(result); Assert.assertEquals(TestResult.Status.PASSED, result.getStatus()); Assert.assertNull(result.getThrowable()); }
@Override public TestResult execute(Class<?> testClass, String methodName) { ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader(); try { // Make sure we run in the context of the arquillian-bundle class loader Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); return super.execute(testClass, methodName); } finally { Thread.currentThread().setContextClassLoader(ctxLoader); } } }