本文整理汇总了Java中org.junit.runner.JUnitCore.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java JUnitCore.addListener方法的具体用法?Java JUnitCore.addListener怎么用?Java JUnitCore.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.junit.runner.JUnitCore
的用法示例。
在下文中一共展示了JUnitCore.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTestsAndAssertCounters
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
/**
* Run the tests in the supplied {@code testClass}, using the specified
* {@link Runner}, and assert the expectations of the test execution.
*
* <p>If the specified {@code runnerClass} is {@code null}, the tests
* will be run with the runner that the test class is configured with
* (i.e., via {@link RunWith @RunWith}) or the default JUnit runner.
*
* @param runnerClass the explicit runner class to use or {@code null}
* if the implicit runner should be used
* @param testClass the test class to run with JUnit
* @param expectedStartedCount the expected number of tests that started
* @param expectedFailedCount the expected number of tests that failed
* @param expectedFinishedCount the expected number of tests that finished
* @param expectedIgnoredCount the expected number of tests that were ignored
* @param expectedAssumptionFailedCount the expected number of tests that
* resulted in a failed assumption
*/
public static void runTestsAndAssertCounters(Class<? extends Runner> runnerClass, Class<?> testClass,
int expectedStartedCount, int expectedFailedCount, int expectedFinishedCount, int expectedIgnoredCount,
int expectedAssumptionFailedCount) throws Exception {
TrackingRunListener listener = new TrackingRunListener();
if (runnerClass != null) {
Constructor<?> constructor = runnerClass.getConstructor(Class.class);
Runner runner = (Runner) BeanUtils.instantiateClass(constructor, testClass);
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
runner.run(notifier);
}
else {
JUnitCore junit = new JUnitCore();
junit.addListener(listener);
junit.run(testClass);
}
assertEquals("tests started for [" + testClass + "]:", expectedStartedCount, listener.getTestStartedCount());
assertEquals("tests failed for [" + testClass + "]:", expectedFailedCount, listener.getTestFailureCount());
assertEquals("tests finished for [" + testClass + "]:", expectedFinishedCount, listener.getTestFinishedCount());
assertEquals("tests ignored for [" + testClass + "]:", expectedIgnoredCount, listener.getTestIgnoredCount());
assertEquals("failed assumptions for [" + testClass + "]:", expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount());
}
示例2: runTaskCase
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
public void runTaskCase() throws Exception {
AbstractCaseData.setCaseData(null);
String caseDataInfo = this.tcr.getTaskCase().getCaseDataInfo();
if (!caseDataInfo.isEmpty()) {
CaseData caseData = AbstractCaseData.getCaseData(caseDataInfo);
LOG.debug("Injecting case data: {} = {}", caseDataInfo, caseData.getValue());
AbstractCaseData.setCaseData(caseData);
}
TaskCase tc = this.tcr.getTaskCase();
LOG.debug("Loading case {}", tc.format());
CaseRunListener trl = new CaseRunListener(this.db, this.tcr);
JUnitCore core = new JUnitCore();
core.addListener(trl);
core.run(Request.method(Class.forName(tc.getCaseClass()), tc.getCaseMethod()));
}
示例3: runTests
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public void runTests(String outputDir) {
JUnitCore junit = new JUnitCore();
if (outputDir == null) {
junit.addListener(new TextListener(System.out));
} else {
junit.addListener(new JUnitResultFormatterAsRunListener(new XMLJUnitResultFormatter()) {
@Override
public void testStarted(Description description) throws Exception {
formatter.setOutput(new FileOutputStream(
new File(outputDir, "TEST-" + description.getDisplayName() + ".xml")));
super.testStarted(description);
}
});
}
junit.run(TestContainer.class);
}
示例4: testSystem
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void testSystem() throws Throwable {
Computer computer = new Computer();
JUnitCore jUnitCore = new JUnitCore();
ByteArrayOutputStream capture = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(capture);
TextListener listener = new TextListener(printStream);
jUnitCore.addListener(listener);
PrintStream systemOut = System.out;
System.setOut(printStream);
try {
jUnitCore.run(computer, ExampleTest.class);
} finally {
System.setOut(systemOut);
}
String output = capture.toString("UTF-8");
output = normalizeOutput(output);
String expectedOutput = getResource("/CompositeTest.testSystem.expected.txt");
Assert.assertEquals(expectedOutput, output);
}
示例5: shouldReportDescriptionsinCorrectOrder
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void shouldReportDescriptionsinCorrectOrder() {
JUnitCore jUnit = new JUnitCore();
jUnit.addListener(new RunListener() {
@Override
public void testRunStarted(Description description) throws Exception {
suiteDescription = description;
}
});
jUnit.run(CuppaRunnerTest.TestsAndTestBlocks.class);
List<Description> rootDescriptionChildren = suiteDescription
.getChildren().get(0).getChildren().get(0).getChildren();
assertThat(rootDescriptionChildren).hasSize(3);
assertThat(rootDescriptionChildren.get(0).getDisplayName()).startsWith("a");
assertThat(rootDescriptionChildren.get(1).getDisplayName()).startsWith("b");
assertThat(rootDescriptionChildren.get(2).getDisplayName()).startsWith("when c");
assertThat(rootDescriptionChildren.get(2).getChildren().get(0).getDisplayName()).startsWith("d");
}
示例6: run
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public boolean run() throws IOException {
try {
m_dir = "testout/junit-" + m_timestamp + "/" + m_testClazz.getCanonicalName() + "/";
new File(m_dir).mkdirs();
// redirect std out/err to files
m_out.addOutputStream(new File(m_dir + "fulloutput.txt"));
System.setOut(new PrintStream(m_out, true));
System.setErr(new PrintStream(m_out, true));
JUnitCore junit = new JUnitCore();
junit.addListener(this);
Result r = junit.run(m_testClazz);
STDOUT.printf("RESULTS: %d/%d\n", r.getRunCount() - r.getFailureCount(), r.getRunCount());
return true;
}
catch (Exception e) {
return false;
}
finally {
m_out.flush();
System.setOut(STDOUT);
System.setErr(STDERR);
m_out.close();
}
}
示例7: prepare
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Before
public void prepare() {
results = new AllureResultsWriterStub();
AllureLifecycle lifecycle = new AllureLifecycle(results);
StepsAspects.setLifecycle(lifecycle);
AllureJunit4 listener = new AllureJunit4(lifecycle);
core = new JUnitCore();
core.addListener(listener);
}
示例8: doWork
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
protected int doWork() throws Exception {
//this is called from the command line, so we should set to use the distributed cluster
IntegrationTestingUtility.setUseDistributedCluster(conf);
Class<?>[] classes = findIntegrationTestClasses();
LOG.info("Found " + classes.length + " integration tests to run:");
for (Class<?> aClass : classes) {
LOG.info(" " + aClass);
}
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
Result result = junit.run(classes);
return result.wasSuccessful() ? 0 : 1;
}
示例9: runTest
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
public synchronized void runTest(IContext context, UnitTest unitTest) throws ClassNotFoundException, CoreException
{
TestSuite testSuite = unitTest.getUnitTest_TestSuite();
/**
* Is Mf
*/
if (unitTest.getIsMf()) {
try {
runMfSetup(testSuite);
runMicroflowTest(unitTest.getName(), unitTest);
}
finally {
runMfTearDown(testSuite);
}
}
/**
* Is java
*/
else {
Class<?> test = Class.forName(unitTest.getName().split("/")[0]);
JUnitCore junit = new JUnitCore();
junit.addListener(new UnitTestRunListener(context, testSuite));
junit.run(test);
}
}
示例10: run
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
/**
* Runs the test classes given in {@param classes}.
* @returns Zero if all tests pass, non-zero otherwise.
*/
public static int run(String[] classes, RunListener listener, DopplJunitListener dopplListener)
{
try
{
JUnitCore junitCore = new JUnitCore();
if(listener != null)
junitCore.addListener(listener);
boolean hasError = false;
Result result;
List<ResultContainer> resultList = new ArrayList<>(classes.length);
for (String c : classes) {
System.out.println("\n\n********** Running "+ c +" **********");
if(dopplListener != null)
dopplListener.startRun(c);
result = runSpecificTest(junitCore, c);
if(dopplListener != null)
dopplListener.endRun(c);
resultList.add(new ResultContainer(result, c));
hasError = hasError || !result.wasSuccessful();
}
return runInner(resultList, hasError);
}
catch(ClassNotFoundException e)
{
throw new RuntimeException(e);
}
}
示例11: runTests
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
private static Result runTests(Injector injector, Class<?>[] testClasses, Optional<Description> testFilter) throws InitializationError {
final JUnitCore junit = new JUnitCore();
junit.addListener(new JUnitRunListener(LOGGER));
final Request testRequest = Request.runner(new Suite(new GuiceInjectionJUnitRunner(injector), testClasses));
if (testFilter.isPresent()) {
return junit.run(testRequest.filterWith(testFilter.get()));
} else {
return junit.run(testRequest);
}
}
示例12: doWork
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Override
protected int doWork() throws Exception {
//this is called from the command line, so we should set to use the distributed cluster
IntegrationTestingUtility.setUseDistributedCluster(conf);
Class<?>[] classes = findIntegrationTestClasses();
LOG.info("Found " + classes.length + " integration tests to run");
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
Result result = junit.run(classes);
return result.wasSuccessful() ? 0 : 1;
}
示例13: launchInProcess
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
private static JkTestSuiteResult launchInProcess(Class<?>[] classes,
boolean printEachTestOnConsole, JunitReportDetail reportDetail, File reportDir,
boolean restoreSystemOut) {
final JUnitCore jUnitCore = new JUnitCore();
if (reportDetail.equals(JunitReportDetail.FULL)) {
jUnitCore.addListener(new JUnitReportListener(reportDir.toPath()));
}
final PrintStream out = System.out;
final PrintStream err = System.err;
if (printEachTestOnConsole) {
jUnitCore.addListener(new JUnitConsoleListener());
} else if (!JkLog.verbose()) {
System.setErr(JkUtilsIO.nopPrintStream());
System.setOut(JkUtilsIO.nopPrintStream());
}
final Properties properties = (Properties) System.getProperties().clone();
final long start = System.nanoTime();
final Result result;
try {
result = jUnitCore.run(classes);
} finally {
if (restoreSystemOut) {
System.setErr(err);
System.setOut(out);
}
}
final long durationInMillis = JkUtilsTime.durationInMillis(start);
return JkTestSuiteResult.fromJunit4Result(properties, "all", result, durationInMillis);
}
示例14: runTestCaseWithMockListener
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
protected RunListener runTestCaseWithMockListener(Class<?> testCase, Description subCase)
throws InitializationError {
RunListener listener = Mockito.mock(RunListener.class);
JUnitCore core = new JUnitCore();
core.addListener(listener);
core.run(Request.runner(new TheorySuite(testCase)).filterWith(subCase));
return listener;
}
示例15: shouldReportCorrectDescriptionsOfSuite
import org.junit.runner.JUnitCore; //导入方法依赖的package包/类
@Test
public void shouldReportCorrectDescriptionsOfSuite() {
JUnitCore jUnit = new JUnitCore();
jUnit.addListener(new RunListener() {
@Override
public void testRunStarted(Description description) throws Exception {
suiteDescription = description;
}
});
jUnit.run(CuppaRunnerTest.PassingTest.class);
assertThat(suiteDescription).isNotNull();
assertThat(suiteDescription.isSuite()).isTrue();
assertThat(suiteDescription.getChildren()).hasSize(1);
Description cuppaDescription = suiteDescription.getChildren().get(0);
assertThat(cuppaDescription.isSuite()).isTrue();
assertThat(cuppaDescription.getDisplayName()).isEqualTo(CuppaRunnerTest.PassingTest.class.getName());
assertThat(cuppaDescription.getChildren()).hasSize(1);
Description describeDescription = cuppaDescription.getChildren().get(0);
assertThat(describeDescription.isSuite()).isTrue();
assertThat(describeDescription.getDisplayName()).isEqualTo("Cuppa");
assertThat(describeDescription.getChildren()).hasSize(1);
Description whenDescription = describeDescription.getChildren().get(0);
assertThat(whenDescription.isSuite()).isTrue();
assertThat(whenDescription.getDisplayName()).isEqualTo("when running with CuppaRunner");
assertThat(whenDescription.getChildren()).hasSize(1);
Description testDescription = whenDescription.getChildren().get(0);
assertThat(testDescription.isTest()).isTrue();
assertThat(testDescription.getDisplayName()).isEqualTo("shows a passing test as passing("
+ CuppaRunnerTest.PassingTest.class.getName() + ")");
assertThat(testDescription.getTestClass()).isEqualTo(CuppaRunnerTest.PassingTest.class);
}