本文整理汇总了Java中org.junit.runner.notification.Failure类的典型用法代码示例。如果您正苦于以下问题:Java Failure类的具体用法?Java Failure怎么用?Java Failure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Failure类属于org.junit.runner.notification包,在下文中一共展示了Failure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFailure
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Override
public void testFailure(Failure failure) throws Exception {
TestDescriptorInternal testInternal;
synchronized (lock) {
testInternal = executing.get(failure.getDescription());
}
boolean needEndEvent = false;
if (testInternal == null) {
// This can happen when, for example, a @BeforeClass or @AfterClass method fails
needEndEvent = true;
testInternal = nullSafeDescriptor(idGenerator.generateId(), failure.getDescription());
resultProcessor.started(testInternal, startEvent());
}
resultProcessor.failure(testInternal.getId(), failure.getException());
if (needEndEvent) {
resultProcessor.completed(testInternal.getId(), new TestCompleteEvent(timeProvider.getCurrentTime()));
}
}
示例2: testFailure
import org.junit.runner.notification.Failure; //导入依赖的package包/类
/**
* Called when an atomic test fails.
*
* @param failure
* describes the test that failed and the exception that was thrown
*/
@Override
public void testFailure(Failure failure) throws Exception {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
N4IDEXpectView view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
view.notifyFailedExecutionOf(failure);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
}
});
}
示例3: testAssumptionFailure
import org.junit.runner.notification.Failure; //导入依赖的package包/类
/**
* Called when an atomic test flags that it assumes a condition that is false
*
* describes the test that failed and the {@link AssumptionViolatedException} that was thrown
*/
@Override
public void testAssumptionFailure(Failure failure) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
N4IDEXpectView view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
view.notifyFailedExecutionOf(failure);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
}
});
}
示例4: endTest
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Override public void endTest(final PlaybackResult result) {
if (!exploratoryTest) {
Platform.runLater(new Runnable() {
@Override public void run() {
resultPane.addResult(result);
}
});
}
if (!needReports()) {
return;
}
if (!exploratoryTest && result.hasFailure()) {
MarathonAssertion assertion = new MarathonAssertion(result.failures(), getFilePath());
runListener.testAssumptionFailure(
new Failure(Description.createTestDescription(MarathonTestCase.class, getFilePath()), assertion));
}
TestAttributes.put("test_object", testCase);
runListener.testFinished(Description.createTestDescription(MarathonTestCase.class, getFilePath()));
addScreenCaptures();
}
示例5: testThreadDumpAndDeadlocks
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Test(timeout=30000)
public void testThreadDumpAndDeadlocks() throws Exception {
new Deadlock();
String s = null;
while (true) {
s = TimedOutTestsListener.buildDeadlockInfo();
if (s != null)
break;
Thread.sleep(100);
}
Assert.assertEquals(3, countStringOccurrences(s, "BLOCKED"));
Failure failure = new Failure(
null, new Exception(TimedOutTestsListener.TEST_TIMED_OUT_PREFIX));
StringWriter writer = new StringWriter();
new TimedOutTestsListener(new PrintWriter(writer)).testFailure(failure);
String out = writer.toString();
Assert.assertTrue(out.contains("THREAD DUMP"));
Assert.assertTrue(out.contains("DEADLOCKS DETECTED"));
System.out.println(out);
}
示例6: testFailure
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Override
public void testFailure(Failure failure) throws Exception {
// Ignore assumptions.
if (failure.getException() instanceof AssumptionViolatedException) {
return;
}
final StringBuilder b = new StringBuilder("REPRODUCE WITH: gradle ");
String task = System.getProperty("tests.task");
// TODO: enforce (intellij still runs the runner?) or use default "test" but that won't work for integ
b.append(task);
GradleMessageBuilder gradleMessageBuilder = new GradleMessageBuilder(b);
gradleMessageBuilder.appendAllOpts(failure.getDescription());
// Client yaml suite tests are a special case as they allow for additional parameters
if (ESClientYamlSuiteTestCase.class.isAssignableFrom(failure.getDescription().getTestClass())) {
gradleMessageBuilder.appendClientYamlSuiteProperties();
}
System.err.println(b.toString());
}
示例7: testAssumptionFailure
import org.junit.runner.notification.Failure; //导入依赖的package包/类
/**
* (non-Javadoc)
* @see org.junit.runner.notification.RunListener#testAssumptionFailure(org.junit.runner.notification.Failure)
*/
@Override
public void testAssumptionFailure( Failure failure ) {
if (log.isDebugEnabled()) {
log.debug("testAssumptionFailure(): Test failed: " + failure.toString() + "| Description: "
+ failure.getDescription());
}
log.info("Test assumption failure received. It will be stored in DB as test failed event.");
try {
testFailure(failure);
} catch (Exception e) {
log.error("Error while processing testFailure event", e);
}
super.testAssumptionFailure(failure);
}
示例8: main
import org.junit.runner.notification.Failure; //导入依赖的package包/类
public static void main(String[] args) {
final Result result =
JUnitCore.runClasses(
codeu.chat.common.SecretTest.class,
codeu.chat.relay.ServerTest.class,
codeu.chat.server.BasicControllerTest.class,
codeu.chat.server.RawControllerTest.class,
codeu.chat.util.TimeTest.class,
codeu.chat.util.TokenizerTest.class,
codeu.chat.util.UuidTest.class,
codeu.chat.util.store.StoreTest.class
);
for (final Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
示例9: isKnownIssue
import org.junit.runner.notification.Failure; //导入依赖的package包/类
private boolean isKnownIssue(Failure failure) {
if (failure == null) {
return false;
}
if (failure.getDescription() == null) {
return false;
}
final KnownIssue knownIssue = failure.getDescription().getAnnotation(KnownIssue.class);
final String message = failure.getMessage();
if (knownIssue == null || message == null || knownIssue.value() == null) {
return false;
}
if (message.contains(knownIssue.value())) {
return true;
}
return false;
}
示例10: runChild
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Override
protected void runChild(final ArchTestExecution child, final RunNotifier notifier) {
ExpectedViolation expectedViolation = ExpectedViolation.none();
HandlingAssertion handlingAssertion = HandlingAssertion.none();
Description description = describeChild(child);
notifier.fireTestStarted(description);
try {
ExpectedViolationDefinition violationDefinition = extractExpectedConfiguration(child);
violationDefinition.configure(expectedViolation);
violationDefinition.configure(handlingAssertion);
expectedViolation.apply(new IntegrationTestStatement(child, handlingAssertion), description).evaluate();
} catch (Throwable throwable) {
notifier.fireTestFailure(new Failure(description, throwable));
} finally {
notifier.fireTestFinished(description);
}
}
示例11: runTestSuiteAgainst
import org.junit.runner.notification.Failure; //导入依赖的package包/类
/**
* Creates and runs a JUnit test runner for testSuite.
*
* @param testSuite the class defining test cases to run
* @param view a UI component to report test failures to
* @return the counts of failures and total test cases.
*/
static RunResult runTestSuiteAgainst(Class testSuite, View view)
{
if(testSuite == null)
throw new NullPointerException("testSuite");
if(view == null)
throw new NullPointerException("view");
Result result = new JUnitCore().run(testSuite);
if (result.getFailureCount() > 0)
{
for (Failure f : result.getFailures())
view.declarePassProgramTestFailure(f.getTrace());
}
return new RunResult(result.getFailureCount(), result.getRunCount());
}
示例12: failsWithExpectedTimeoutButWrongError
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Test
public void failsWithExpectedTimeoutButWrongError() {
Result result = TestRunner.runTest(FailsWithExpectedTimeoutButWrongError.class);
assertThat(result.wasSuccessful()).isFalse();
List<Failure> failures = result.getFailures();
assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1);
Failure failure = failures.get(0);
String expectedMessage = "\n"
+ "Expected: (an instance of java.util.concurrent.TimeoutException and exception with message a string containing \"this is a message for FailsWithExpectedTimeoutButWrongError\")"
+ "\n" + " "
+ "but: an instance of java.util.concurrent.TimeoutException <java.lang.NullPointerException> is a java.lang.NullPointerException";
assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class)
.hasMessageContaining(expectedMessage);
}
示例13: testThreadDumpAndDeadlocks
import org.junit.runner.notification.Failure; //导入依赖的package包/类
@Test(timeout=500)
public void testThreadDumpAndDeadlocks() throws Exception {
new Deadlock();
String s = null;
while (true) {
s = TimedOutTestsListener.buildDeadlockInfo();
if (s != null)
break;
Thread.sleep(100);
}
Assert.assertEquals(3, countStringOccurrences(s, "BLOCKED"));
Failure failure = new Failure(
null, new Exception(TimedOutTestsListener.TEST_TIMED_OUT_PREFIX));
StringWriter writer = new StringWriter();
new TimedOutTestsListener(new PrintWriter(writer)).testFailure(failure);
String out = writer.toString();
Assert.assertTrue(out.contains("THREAD DUMP"));
Assert.assertTrue(out.contains("DEADLOCKS DETECTED"));
System.out.println(out);
}
示例14: main
import org.junit.runner.notification.Failure; //导入依赖的package包/类
public static void main(String[] args) {
final Result result =
JUnitCore.runClasses(
codeu.chat.common.SecretTest.class,
codeu.chat.relay.ServerTest.class,
codeu.chat.server.BasicControllerTest.class,
codeu.chat.server.RawControllerTest.class,
codeu.chat.util.TimeTest.class,
codeu.chat.util.UuidTest.class,
codeu.chat.util.store.StoreTest.class
);
for (final Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
示例15: createListener
import org.junit.runner.notification.Failure; //导入依赖的package包/类
private static JUnit4TestListener createListener(final StringBuffer buf) {
return new JUnit4TestListener(new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
buf.append(new String(new byte[]{(byte)b}));
}
})) {
@Override
protected long currentTime() {
return 0;
}
@Override
protected String getTrace(Failure failure) {
return StringUtil.convertLineSeparators(super.getTrace(failure));
}
};
}