本文整理汇总了Java中org.junit.runner.notification.RunNotifier.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java RunNotifier.addListener方法的具体用法?Java RunNotifier.addListener怎么用?Java RunNotifier.addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.junit.runner.notification.RunNotifier
的用法示例。
在下文中一共展示了RunNotifier.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
final void run(final RunNotifier notifier) {
RunNotifier nested = new RunNotifier();
NestedRunListener nestedListener = new NestedRunListener(notifier);
nested.addListener(nestedListener);
try {
runEnabledTests(nested);
} finally {
nestedListener.cleanup();
}
for (Description disabledTest : disabledTests) {
nested.fireTestStarted(disabledTest);
nested.fireTestIgnored(disabledTest);
}
}
示例2: executeTestClass
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
private static void executeTestClass(Class<?> testClass) throws Throwable {
Throwable[] throwables = new Throwable[1];
WebTesterJUnitRunner runner = new WebTesterJUnitRunner(testClass);
RunNotifier notifier = new RunNotifier();
notifier.addListener(new RunListener() {
public void testFailure(Failure failure) throws Exception {
System.out.println("testFailure");
throwables[0] = failure.getException();
}
});
runner.run(notifier);
if (throwables[0] != null) {
throw throwables[0];
}
}
示例3: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Test
public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
jAnnotation.param("unitName", "test-unit-1");
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
示例4: addListener
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@After("execution(org.junit.runner.notification.RunNotifier.new())")
public void addListener(final JoinPoint point) {
final RunNotifier notifier = (RunNotifier) point.getThis();
notifier.removeListener(allure);
notifier.addListener(allure);
}
示例5: run
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Override
public void run(RunNotifier notifier) {
// To avoid duplicates need to do N-1 times if there's N levels of these suites
// Note, in this notifier implementation it does not matter if we try to remove
// a listener if is not contained with the notifier
notifier.removeListener(listener);
notifier.addListener(listener);
super.run(notifier);
notifier.removeListener(listener);
}
示例6: testClassWithPersistenceContextWithoutUnitNameSpecified
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Test
public void testClassWithPersistenceContextWithoutUnitNameSpecified() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
emField.annotate(PersistenceContext.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
final JpaUnitRunner runner = new JpaUnitRunner(cut);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class);
verify(listener).testFailure(failureCaptor.capture());
final Failure failure = failureCaptor.getValue();
assertThat(failure.getException().getClass(), equalTo(JpaUnitException.class));
assertThat(failure.getException().getMessage(), containsString("No Persistence"));
}
示例7: run
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Override
public void run(RunNotifier notifier) {
if (isItFailedTestsRerun && !canRerunFailedTests()) {
shutdownRerun(notifier);
} else {
if (storeFailedResults) {
notifier.addListener(new BobcumberListener(this));
}
super.run(notifier);
closeWebDriverPool();
}
}
示例8: executeTestMethod
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
/**
* This method allows access to the test invocation, from within the modules (who get a reference to the runner
* via the context). We do not check for listeners veto's (typically, these modules will veto the execution of
* the test in normal execution mode, and call this method later on to do their logic).
*
* @param testObject
* @param method
*/
public void executeTestMethod(Object testObject, Method method) {
TestMethod testMethod = wrapMethod(method);
RunNotifier notifier = new RunNotifier();
InterceptingListener listener = new InterceptingListener();
notifier.addListener(listener);
Description description = methodDescription(method);
createMethodRoadie(testObject, method, testMethod, notifier, description).run();
if(listener.isFailed()) {
StringBuilder msg = new StringBuilder("Exeception while executing ");
msg.append(method.getName()).append(": ").append(listener.getFailure().getDescription());
throw new UnitilsException(msg.toString(),listener.getFailure().getException());
}
}
示例9: main
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Result result = new Result();
RunNotifier runNotifier = new RunNotifier();
runNotifier.addListener(result.createListener());
JUnit4ClassRunner classRunner = new JUnit4ClassRunner(UnitilsIntegrationTest.class);
classRunner.run(runNotifier);
if (result.getFailureCount() > 0) {
registerFailure();
}
}
示例10: runTests
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
public void runTests(Class<?>... testClasses) throws Exception {
result = new Result();
RunNotifier runNotifier = new RunNotifier();
runNotifier.addListener(result.createListener());
for (Class<?> testClass : testClasses) {
UnitilsJUnit4TestClassRunner testClassRunner = new TestUnitilsJUnit4TestClassRunner(testClass);
testClassRunner.run(runNotifier);
}
}
示例11: testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Test
public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule");
ruleField.annotate(Rule.class);
final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()"));
ruleField.init(instance);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class);
jAnnotation.param("unitName", "test-unit-1");
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
示例12: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Test
public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class);
jAnnotation.param("unitName", "test-unit-1");
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final JpaUnitRunner runner = new JpaUnitRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
示例13: run
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void run(final RunNotifier notifier) {
try {
notifier.removeListener(testRunRecording); // remove existing listeners that could be added by suite or class runners
notifier.addListener(testRunRecording);
super.run(notifier);
} finally {
notifier.removeListener(testRunRecording);
}
}
示例14: testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Test
public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf");
final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class);
jAnnotation.param("unitName", "test-unit-1");
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final JpaUnitRunner runner = new JpaUnitRunner(cut);
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class);
verify(listener).testStarted(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
verify(listener).testFinished(descriptionCaptor.capture());
assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest"));
assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod"));
}
示例15: testClassWithPersistenceContextAndPersistenceUnitFields
import org.junit.runner.notification.RunNotifier; //导入方法依赖的package包/类
@Test
public void testClassWithPersistenceContextAndPersistenceUnitFields() throws Exception {
// GIVEN
final JCodeModel jCodeModel = new JCodeModel();
final JPackage jp = jCodeModel.rootPackage();
final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
jAnnotationUse.param("value", JpaUnitRunner.class);
final JFieldVar emf1Field = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
emf1Field.annotate(PersistenceContext.class);
final JFieldVar emf2Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf");
emf2Field.annotate(PersistenceUnit.class);
final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod");
jMethod.annotate(Test.class);
buildModel(testFolder.getRoot(), jCodeModel);
compileModel(testFolder.getRoot());
final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name());
final RunListener listener = mock(RunListener.class);
final RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
final JpaUnitRunner runner = new JpaUnitRunner(cut);
// WHEN
runner.run(notifier);
// THEN
final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class);
verify(listener).testFailure(failureCaptor.capture());
final Failure failure = failureCaptor.getValue();
assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class));
assertThat(failure.getException().getMessage(), containsString("either @PersistenceUnit or @PersistenceContext"));
}