本文整理匯總了Java中org.junit.runner.Description.createTestDescription方法的典型用法代碼示例。如果您正苦於以下問題:Java Description.createTestDescription方法的具體用法?Java Description.createTestDescription怎麽用?Java Description.createTestDescription使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.junit.runner.Description
的用法示例。
在下文中一共展示了Description.createTestDescription方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: TrisotechTCKTestRunner
import org.junit.runner.Description; //導入方法依賴的package包/類
protected TrisotechTCKTestRunner(Properties properties, Class<TrisotechTCKTest> testClass, String category, String testId, String testCase,
File testCaseFile, File resultCSV) throws InitializationError {
super(testClass);
this.properties = properties;
this.category = category;
this.testId = testId;
this.testCase = testCase;
this.testCaseFile = testCaseFile;
this.resultCSV = resultCSV;
runnerDescription = Description.createSuiteDescription(category + " - " + testCase);
try {
TestCases tcs = TckMarshallingHelper.load(new FileInputStream(testCaseFile));
modelName = tcs.getModelName();
for (TestCase tc : tcs.getTestCase()) {
Description testDescription = Description.createTestDescription(testClass, testCase + " - " + tc.getId());
TrisotechTCKTest myTest = testClass.newInstance();
myTest.setId(tc.getId());
myTest.setDescription(testDescription);
testCases.add(myTest);
runnerDescription.addChild(testDescription);
}
} catch (FileNotFoundException | JAXBException | InstantiationException | IllegalAccessException e) {
throw new InitializationError(e);
}
}
示例2: shouldRun
import org.junit.runner.Description; //導入方法依賴的package包/類
@Override
public boolean shouldRun(final Description description) {
if (description.isTest()) {
return delegate.shouldRun(description);
}
// explicitly check if any children want to run
for (Description child : description.getChildren()) {
if (shouldRun(child)) {
return true;
}
//Intellij bug, we get the wrong description, let us test with a slightly modified one now
final Description relaxed = Description.createTestDescription(
child.getTestClass(), getMethodName(child.getDisplayName())
);
if (shouldRun(relaxed)) {
return true;
}
}
return false;
}
示例3: reportHelperWillComplainIfMoreThanOneIsActive
import org.junit.runner.Description; //導入方法依賴的package包/類
@Test
public void reportHelperWillComplainIfMoreThanOneIsActive() {
TestableEventReporter eventReporter = new TestableEventReporter();
Description description = Description.createTestDescription(this.getClass().getCanonicalName(), "name");
ReportHelper firstHelper = new ReportHelper(eventReporter);
ReportHelper nextHelper = new ReportHelper(eventReporter);
firstHelper.starting(description);
// Its ok to stop using a helper and use another one
nextHelper.starting(description);
// but we should fail if we ever use it again
try {
firstHelper.finished(description);
fail("Expected an IllegalArgumentException because there is more than one reporter active");
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("@Rules"));
}
}
示例4: testTestRunStartedSupportsClassInDefaultPackage
import org.junit.runner.Description; //導入方法依賴的package包/類
public void testTestRunStartedSupportsClassInDefaultPackage() throws Exception {
LoggingListener loggingListener = new LoggingListener();
Description description = Description.createTestDescription(Class.forName("Dummy"), "dummy");
// Will throw an exception without the check for testClassPackage != null in testRunStarted
loggingListener.testRunStarted(description);
}
示例5: testCustomLevelPerMethod
import org.junit.runner.Description; //導入方法依賴的package包/類
public void testCustomLevelPerMethod() throws Exception {
LoggingListener loggingListener = new LoggingListener();
Description suiteDescription = Description.createSuiteDescription(TestClass.class);
Logger xyzLogger = Loggers.getLogger("xyz");
Logger abcLogger = Loggers.getLogger("abc");
final Level level = ESLoggerFactory.getRootLogger().getLevel();
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
loggingListener.testRunStarted(suiteDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
Method method = TestClass.class.getMethod("annotatedTestMethod");
TestLogging annotation = method.getAnnotation(TestLogging.class);
Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod", annotation);
loggingListener.testStarted(testDescription);
assertThat(xyzLogger.getLevel(), equalTo(Level.TRACE));
assertThat(abcLogger.getLevel(), equalTo(level));
loggingListener.testFinished(testDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
loggingListener.testRunFinished(new Result());
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
}
示例6: testInvalidMethodTestLoggingAnnotation
import org.junit.runner.Description; //導入方法依賴的package包/類
public void testInvalidMethodTestLoggingAnnotation() throws Exception {
final LoggingListener loggingListener = new LoggingListener();
final Description suiteDescription = Description.createSuiteDescription(InvalidMethod.class);
loggingListener.testRunStarted(suiteDescription);
final Method method = InvalidMethod.class.getMethod("invalidMethod");
final TestLogging annotation = method.getAnnotation(TestLogging.class);
Description testDescription = Description.createTestDescription(InvalidMethod.class, "invalidMethod", annotation);
final IllegalArgumentException e =
expectThrows(IllegalArgumentException.class, () -> loggingListener.testStarted(testDescription));
assertThat(e.getMessage(), equalTo("invalid test logging annotation [abc:INFO:WARN]"));
}
示例7: getMethodDescriptions
import org.junit.runner.Description; //導入方法依賴的package包/類
private List<Description> getMethodDescriptions(final Runner runner) {
final String displayName = runner.getDescription().getDisplayName();
final List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(Test.class);
List<Description> descriptions = new ArrayList<Description>();
for (FrameworkMethod method : methods) {
final Description description = Description.createTestDescription(getTestClass().getJavaClass(), method.getName() + displayName, method.getAnnotations());
descriptions.add(description);
}
return descriptions;
}
示例8: testJSJVMBackendFrameworkMethod
import org.junit.runner.Description; //導入方法依賴的package包/類
private void testJSJVMBackendFrameworkMethod(FrameworkMethod aFrameworkMethod, RunNotifier aRunNotifier) {
Description theDescription = Description.createTestDescription(testClass.getJavaClass(), aFrameworkMethod.getName() + " JVM Target");
aRunNotifier.fireTestStarted(theDescription);
try {
// Simply invoke using reflection
Object theInstance = testClass.getJavaClass().getDeclaredConstructor().newInstance();
Method theMethod = aFrameworkMethod.getMethod();
theMethod.invoke(theInstance);
aRunNotifier.fireTestFinished(theDescription);
} catch (Exception e) {
aRunNotifier.fireTestFailure(new Failure(theDescription, e));
}
}
示例9: testCustomLevelPerClass
import org.junit.runner.Description; //導入方法依賴的package包/類
public void testCustomLevelPerClass() throws Exception {
LoggingListener loggingListener = new LoggingListener();
Description suiteDescription = Description.createSuiteDescription(AnnotatedTestClass.class);
Logger abcLogger = Loggers.getLogger("abc");
Logger xyzLogger = Loggers.getLogger("xyz");
// we include foo and foo.bar to maintain that logging levels are applied from the top of the hierarchy down; this ensures that
// setting the logging level for a parent logger and a child logger applies the parent level first and then the child as otherwise
// setting the parent level would overwrite the child level
Logger fooLogger = Loggers.getLogger("foo");
Logger fooBarLogger = Loggers.getLogger("foo.bar");
final Level level = ESLoggerFactory.getRootLogger().getLevel();
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
assertThat(fooLogger.getLevel(), equalTo(level));
assertThat(fooBarLogger.getLevel(), equalTo(level));
loggingListener.testRunStarted(suiteDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
assertThat(fooLogger.getLevel(), equalTo(Level.WARN));
assertThat(fooBarLogger.getLevel(), equalTo(Level.ERROR));
Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "test");
loggingListener.testStarted(testDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
assertThat(fooLogger.getLevel(), equalTo(Level.WARN));
assertThat(fooBarLogger.getLevel(), equalTo(Level.ERROR));
loggingListener.testFinished(testDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
assertThat(fooLogger.getLevel(), equalTo(Level.WARN));
assertThat(fooBarLogger.getLevel(), equalTo(Level.ERROR));
loggingListener.testRunFinished(new Result());
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
assertThat(fooLogger.getLevel(), equalTo(level));
assertThat(fooBarLogger.getLevel(), equalTo(level));
}
示例10: testCustomLevelPerClassAndPerMethod
import org.junit.runner.Description; //導入方法依賴的package包/類
public void testCustomLevelPerClassAndPerMethod() throws Exception {
LoggingListener loggingListener = new LoggingListener();
Description suiteDescription = Description.createSuiteDescription(AnnotatedTestClass.class);
Logger abcLogger = Loggers.getLogger("abc");
Logger xyzLogger = Loggers.getLogger("xyz");
final Level level = ESLoggerFactory.getRootLogger().getLevel();
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
loggingListener.testRunStarted(suiteDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
Method method = TestClass.class.getMethod("annotatedTestMethod");
TestLogging annotation = method.getAnnotation(TestLogging.class);
Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod", annotation);
loggingListener.testStarted(testDescription);
assertThat(xyzLogger.getLevel(), equalTo(Level.TRACE));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
loggingListener.testFinished(testDescription);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
Method method2 = TestClass.class.getMethod("annotatedTestMethod2");
TestLogging annotation2 = method2.getAnnotation(TestLogging.class);
Description testDescription2 = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod2", annotation2);
loggingListener.testStarted(testDescription2);
assertThat(xyzLogger.getLevel(), equalTo(Level.DEBUG));
assertThat(abcLogger.getLevel(), equalTo(Level.TRACE));
loggingListener.testFinished(testDescription2);
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
loggingListener.testRunFinished(new Result());
assertThat(xyzLogger.getLevel(), equalTo(level));
assertThat(abcLogger.getLevel(), equalTo(level));
}
示例11: describeChild
import org.junit.runner.Description; //導入方法依賴的package包/類
@Override
public Description describeChild(Spec child) {
return Description.createTestDescription(this.getTestClass().getJavaClass(), child.getFullDescription());
}
示例12: describeChild
import org.junit.runner.Description; //導入方法依賴的package包/類
@Override
protected Description describeChild(FrameworkMethod frameworkMethod) {
return Description.createTestDescription(testClass.getJavaClass(), frameworkMethod.getName());
}
示例13: describeSelf
import org.junit.runner.Description; //導入方法依賴的package包/類
@Override
Description describeSelf() {
return Description.createTestDescription(testClass, testMethod.getName());
}
示例14: describeSelf
import org.junit.runner.Description; //導入方法依賴的package包/類
@Override
Description describeSelf() {
return Description.createTestDescription(testClass, ruleField.getName());
}