当前位置: 首页>>代码示例>>Java>>正文


Java Failure.getException方法代码示例

本文整理汇总了Java中org.junit.runner.notification.Failure.getException方法的典型用法代码示例。如果您正苦于以下问题:Java Failure.getException方法的具体用法?Java Failure.getException怎么用?Java Failure.getException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.junit.runner.notification.Failure的用法示例。


在下文中一共展示了Failure.getException方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:ReproduceInfoPrinter.java

示例2: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
/**
 * Called when an atomic case fails.
 *
 * @param failure describes the case that failed and the exception that was thrown
 *
 * @throws Exception for various issues
 */
@Override
public void testFailure(Failure failure) throws Exception {
    this.throwable = failure.getException();
    if (!(this.throwable instanceof ToBeImplementedException)) {
        LOG.warn("{} {}", failure.getDescription().getDisplayName(), this.throwable.getMessage());
    }

    if (this.db == null || this.tcr == null) {
        return;
    }
    if (throwable == null) {
        return;
    }

    this.tcr.setException(throwable);
}
 
开发者ID:tascape,项目名称:reactor,代码行数:24,代码来源:CaseRunListener.java

示例3: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
private void testFailure(Failure failure, String messageName, String methodName) {
  final Map attrs = new HashMap();
  attrs.put("name", methodName);
  final long duration = currentTime() - myCurrentTestStart;
  if (duration > 0) {
    attrs.put("duration", Long.toString(duration));
  }
  try {
    final String trace = getTrace(failure);
    final Throwable ex = failure.getException();
    final ComparisonFailureData notification = createExceptionNotification(ex);
    ComparisonFailureData.registerSMAttributes(notification, trace, failure.getMessage(), attrs, ex);
  }
  catch (Throwable e) {
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter writer = new PrintWriter(stringWriter);
    e.printStackTrace(writer);
    ComparisonFailureData.registerSMAttributes(null, stringWriter.toString(), e.getMessage(), attrs, e);
  }
  finally {
    myPrintStream.println("\n" + MapSerializerUtil.asString(messageName, attrs));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:JUnit4TestListener.java

示例4: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
/**
 *
 * @see org.junit.runner.notification.RunListener#testFailure(org.junit.runner.notification.Failure)
 */
@Override
public void testFailure( Failure failure ) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("testFailure(): Test failed: " + failure.toString() + "| Description: "
                  + failure.getDescription());
    }
    try {
        lastStartedMethodIsFailing = true;
        //TODO check if failure.getDescription() represents several methods. This might be in case of exception
        // in @BeforeClass

        // if this is an assertion error, we need to log it
        Throwable failureException = failure.getException();
        if (failureException instanceof AssertionError) {
            logger.error(MSG__TEST_FAILED_ASSERTION_ERROR, failureException); //.getMessage() );
        } else {
            logger.error(MSG__TEST_FAILED, failureException);
        }

        //open a performance test scenario and test case
        logger.endTestcase(TestCaseResult.FAILED);
        sendTestEndEventToAgents();
    } catch (Exception e) {
        try {
            logger.fatal("UNEXPECTED EXCEPTION IN [email protected]", e);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } finally {
        super.testFailure(failure);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:38,代码来源:AtsJunitTestListener.java

示例5: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
@Override
public void testFailure(Failure failure) throws java.lang.Exception {
	boolean isCloudSecurityError = 
			failure.getException() != null && 
			failure.getException() instanceof AccessControlException &&
			((AccessControlException) failure.getException()).getPermission().getName().equals("accessDeclaredMembers");
	
	UnitTest t = getUnitTest(failure.getDescription());

	/** 
	 * Test itself failed
	 */		
	TestManager.LOG.error("Failed test (at step '" + TestManager.instance().getLastReportedStep() + "') " + failure.getDescription().getClassName() + "." + failure.getDescription().getMethodName() + " : " + failure.getMessage(), failure.getException());

	testSuite.setTestFailedCount(testSuite.getTestFailedCount() + 1);
	testSuite.commit();
	
	t.setResult(UnitTestResult._2_Failed);
	t.setResultMessage(String.format("%s %s: %s\n\n:%s",
			isCloudSecurityError ? "CLOUD SECURITY EXCEPTION \n\n" + TestManager.CLOUD_SECURITY_ERROR : "FAILED",
			findProperExceptionLine(failure.getTrace()),
			failure.getMessage(),
			failure.getTrace()
			));
	
	t.setLastStep(TestManager.instance().getLastReportedStep());
	t.setLastRun(new Date());
	t.commit();
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:30,代码来源:UnitTestRunListener.java

示例6: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
@Override
public void testFailure(Failure failure) throws Exception {
    Throwable ex = failure.getException();
    if (ex instanceof OutOfMemoryError) {
        Logging.log.error("Got OOM, dumping thread info");
        printThreadDump();
    } else {
        Logging.log.error("Caught exception {}", ex);
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:11,代码来源:SystemTestRunListener.java

示例7: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
public synchronized void testFailure(Failure failure) throws Exception {
  final Description description = failure.getDescription();
  final Throwable throwable = failure.getException();

  final Throwable cause = throwable.getCause();
  if (ComparisonFailureData.isAssertionError(throwable.getClass()) || 
      ComparisonFailureData.isAssertionError(cause != null ? cause.getClass() : null)) {
    // junit4 makes no distinction between errors and failures
    doAddFailure(description, throwable);
  }

  else {
    prepareDefectPacket(description, throwable).send();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:JUnit4TestResultsSender.java

示例8: testFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
@Override
public void testFailure(Failure failure) throws Exception {
	if (working) {
		if (failure.getDescription().getMethodName() == null) {
			// before class failed
			for (Description child : failure.getDescription().getChildren()) {
				// mark all methods failed
				testFailure(new Failure(child, failure.getException()));
			}
		} else {
			// normal failure
			Element testcase = createTestCase(failure.getDescription());

			Element element;
			if (failure.getException() instanceof AssertionError) {

				if (isKnownIssue(failure)) {
					ignored.incrementAndGet();
					element = xml.createElement("skipped");
				}
				else {
					failures.incrementAndGet();
					element = xml.createElement("failure");
				}
			} else {
				errors.incrementAndGet();
				element = xml.createElement("error");
			}

			testcase.appendChild(element);

			final String message;
			if (isSinceVersion(failure)) {
				message = prependSinceVersionJira(failure, failure.getMessage());
			}
			else {
				message = failure.getMessage();
			}

			element.setAttribute("type", safeString(failure.getException().getClass().getName()));
			element.setAttribute("message", safeString(message));
			element.appendChild(xml.createCDATASection(safeString(failure.getTrace())));

			testsuite.get().appendChild(testcase);
			writeXml();
		}
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:49,代码来源:IntermediateReporter.java

示例9: fireTestFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
@Override
public void fireTestFailure(Failure failure) {
    exception = failure.getException();
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:5,代码来源:ArchUnitIntegrationTestRunner.java

示例10: testAssumptionFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
/**
 * Called when an atomic case flags that it assumes a condition that is false
 *
 * @param failure describes the case that failed and the {@link AssumptionViolatedException} that was thrown
 */
@Override
public void testAssumptionFailure(Failure failure) {
    LOG.error("{}", failure.getTestHeader(), failure.getException());
    this.throwable = failure.getException();
}
 
开发者ID:tascape,项目名称:reactor,代码行数:11,代码来源:CaseRunListener.java

示例11: shouldConvertFailure

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
private boolean shouldConvertFailure(Failure failure) {
     return (failure.getException() instanceof ComparisonFailure);
}
 
开发者ID:MarkBramnik,项目名称:rtest,代码行数:4,代码来源:ProtocolConverter.java

示例12: makeFailureTest

import org.junit.runner.notification.Failure; //导入方法依赖的package包/类
protected CtMethod<?> makeFailureTest(CtMethod<?> test, Failure failure) {
    CtMethod cloneMethodTest = AmplificationHelper.cloneMethodTest(test, "");
    cloneMethodTest.setSimpleName(test.getSimpleName());
    Factory factory = cloneMethodTest.getFactory();

    Throwable exception = failure.getException();
    if (exception instanceof TestTimedOutException || // TestTimedOutException means infinite loop
            exception instanceof AssertionError) { // AssertionError means that some assertion remained in the test: TODO
        return null;
    }

    Class exceptionClass;
    if (exception == null) {
        exceptionClass = Exception.class;
    } else {
        exceptionClass = exception.getClass();
    }

    CtTry tryBlock = factory.Core().createTry();
    tryBlock.setBody(cloneMethodTest.getBody());
    String snippet = "org.junit.Assert.fail(\"" + test.getSimpleName() + " should have thrown " + exceptionClass.getSimpleName() + "\")";
    tryBlock.getBody().addStatement(factory.Code().createCodeSnippetStatement(snippet));
    DSpotUtils.addComment(tryBlock, "AssertGenerator generate try/catch block with fail statement", CtComment.CommentType.INLINE);

    CtCatch ctCatch = factory.Core().createCatch();
    CtTypeReference exceptionType = factory.Type().createReference(exceptionClass);
    ctCatch.setParameter(factory.Code().createCatchVariable(exceptionType, "eee"));

    ctCatch.setBody(factory.Core().createBlock());

    List<CtCatch> catchers = new ArrayList<>(1);
    catchers.add(ctCatch);
    tryBlock.setCatchers(catchers);

    CtBlock body = factory.Core().createBlock();
    body.addStatement(tryBlock);

    cloneMethodTest.setBody(body);
    cloneMethodTest.setSimpleName(cloneMethodTest.getSimpleName() + "_failAssert" + (numberOfFail++));
    Counter.updateAssertionOf(cloneMethodTest, 1);

    AmplificationHelper.getAmpTestToParent().put(cloneMethodTest, test);

    return cloneMethodTest;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:46,代码来源:MethodsAssertGenerator.java


注:本文中的org.junit.runner.notification.Failure.getException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。