下面列出了org.junit.runner.Description#getClassName() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void finished(Description description) {
// Remove the test deployment
try {
TestHelper.annotationDeploymentTearDown(processEngine, deploymentId,
Class.forName(description.getClassName()), description.getMethodName());
} catch (ClassNotFoundException e) {
throw new ActivitiException("Programmatic error: could not instantiate "
+ description.getClassName(), e);
}
// Reset internal clock
processEngineConfiguration.getClock().reset();
// Rest mocks
if (mockSupport != null) {
TestHelper.annotationMockSupportTeardown(mockSupport);
}
}
@Override
protected void starting(Description description)
{
super.starting(description);
basePath = "target/" + description.getClassName() + "/" + description.getMethodName();
applicationPath = basePath + "/app";
try {
FileUtils.forceMkdir(new File(basePath));
} catch (IOException e) {
throw new RuntimeException(e);
}
storageAgent = new AsyncFSStorageAgent(applicationPath, null);
Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
attributes.put(DAG.APPLICATION_PATH, applicationPath);
}
@Override
public boolean evaluateTest(Description description) {
if (methodFilters.isEmpty()) {
return true;
}
String className = description.getClassName();
MethodFilter methodFilter = methodFilters.get(className);
if (methodFilter != null) {
return methodFilter.shouldRun(description);
}
// This test class was not explicitly excluded and none of it's test methods were
// explicitly included or excluded. Should be run, return true:
return true;
}
@Override
protected void failed(final Throwable e, final Description description) {
final String methodName = description.getMethodName();
String className = description.getClassName();
className = className.substring(className.lastIndexOf('.') + 1);
System.out.println(">>>> " + className + " " + methodName + " FAILED due to " + e);
}
@Override
protected void starting(final Description description) {
String methodName = description.getMethodName();
String className = description.getClassName();
className = className.substring(className.lastIndexOf('.') + 1);
// System.out.println("Starting JUnit-test: " + className + " " + methodName);
}
@Override
@SuppressWarnings("unchecked")
protected void starting(Description description) {
String className = description.getClassName();
className = className.replaceAll("Test", "");
Class<? extends ModelElementInstance> instanceClass = null;
try {
instanceClass = (Class<? extends ModelElementInstance>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
modelInstance = Bpmn.createEmptyModel();
model = modelInstance.getModel();
modelElementType = model.getType(instanceClass);
}
protected void finished(Description description) {
// Remove the test deployment
try {
DmnTestHelper.annotationDeploymentTearDown(dmnEngine, deploymentId, Class.forName(description.getClassName()), description.getMethodName());
} catch (ClassNotFoundException e) {
throw new FlowableException("Programmatic error: could not instantiate " + description.getClassName(), e);
}
}
public void startFakeTestCase(Description description) throws IllegalAccessException {
String uid = getSuiteUid(description);
String name = description.isTest() ? description.getMethodName() : description.getClassName();
TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name);
event.setTitle(name);
AnnotationManager am = new AnnotationManager(description.getAnnotations());
am.update(event);
getLifecycle().fire(event);
}
protected void finished(Description description) {
// Remove the test deployment
try {
FormTestHelper.annotationDeploymentTearDown(formEngine, deploymentId, Class.forName(description.getClassName()), description.getMethodName());
} catch (ClassNotFoundException e) {
throw new FlowableException("Programmatic error: could not instantiate " + description.getClassName(), e);
}
}
@Override
@SuppressWarnings("unchecked")
protected void starting(Description description) {
String className = description.getClassName();
className = className.replaceAll("Test", "");
Class<? extends ModelElementInstance> instanceClass = null;
try {
instanceClass = (Class<? extends ModelElementInstance>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
modelInstance = Bpmn.createEmptyModel();
model = modelInstance.getModel();
modelElementType = model.getType(instanceClass);
}
private TestDescription toDescription(Description description) {
return new TestDescription() {
@Override
public String getTestId() {
return description.getDisplayName();
}
@Override
public String getFilesystemFriendlyName() {
return description.getClassName() + "-" + description.getMethodName();
}
};
}
private TestResult createTestResult(final String uuid, final Description description) {
final String className = description.getClassName();
final String methodName = description.getMethodName();
final String name = Objects.nonNull(methodName) ? methodName : className;
final String fullName = Objects.nonNull(methodName) ? String.format("%s.%s", className, methodName) : className;
final String suite = Optional.ofNullable(description.getTestClass())
.map(it -> it.getAnnotation(DisplayName.class))
.map(DisplayName::value).orElse(className);
final TestResult testResult = new TestResult()
.setUuid(uuid)
.setHistoryId(getHistoryId(description))
.setFullName(fullName)
.setName(name);
testResult.getLabels().addAll(getProvidedLabels());
testResult.getLabels().addAll(Arrays.asList(
createPackageLabel(getPackage(description.getTestClass())),
createTestClassLabel(className),
createTestMethodLabel(name),
createSuiteLabel(suite),
createHostLabel(),
createThreadLabel(),
createFrameworkLabel("junit4"),
createLanguageLabel("java")
));
testResult.getLabels().addAll(extractLabels(description));
testResult.getLinks().addAll(extractLinks(description));
getDisplayName(description).ifPresent(testResult::setName);
getDescription(description).ifPresent(testResult::setDescription);
return testResult;
}
@Override
public Statement apply(final Statement base, final Description description) {
// Hack: Using -DEBUG as a JVM param sets a property called "EBUG"...
if (System.getProperties().containsKey("EBUG")) {
StatusLogger.getLogger().setLevel(Level.DEBUG);
}
testClassName = description.getClassName();
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (contextSelectorClass != null) {
System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, contextSelectorClass.getName());
}
// TODO Consider instead of the above:
// LogManager.setFactory(new Log4jContextFactory(LoaderUtil.newInstanceOf(contextSelectorClass)));
System.setProperty(SYS_PROP_KEY_CLASS_NAME, description.getClassName());
System.setProperty(SYS_PROP_KEY_DISPLAY_NAME, description.getDisplayName());
loggerContext = Configurator.initialize(description.getDisplayName(),
description.getTestClass().getClassLoader(), configurationLocation);
try {
base.evaluate();
} finally {
if (!Configurator.shutdown(loggerContext, shutdownTimeout, shutdownTimeUnit)) {
StatusLogger.getLogger().error("Logger context {} did not shutdown completely after {} {}.",
loggerContext.getName(), shutdownTimeout, shutdownTimeUnit);
}
loggerContext = null;
contextSelectorClass = null;
StatusLogger.getLogger().reset();
System.clearProperty(Constants.LOG4J_CONTEXT_SELECTOR);
System.clearProperty(SYS_PROP_KEY_CLASS_NAME);
System.clearProperty(SYS_PROP_KEY_DISPLAY_NAME);
}
}
};
}
@Override
protected void starting(Description description)
{
TestUtils.deleteTargetTestClassFolder(description);
managedState = new MockManagedStateImpl();
applicationPath = "target/" + description.getClassName() + "/" + description.getMethodName();
((FileAccessFSImpl)managedState.getFileAccess()).setBasePath(applicationPath + "/" + "bucket_data");
managedState.setNumBuckets(2);
managedState.setMaxMemorySize(100);
operatorContext = ManagedStateTestUtils.getOperatorContext(1, applicationPath);
}
@Override
protected void starting(Description description)
{
final String methodName = description.getMethodName();
final String className = description.getClassName();
testBase = new SQSTestBase();
if (testBase.validateTestCreds() == false) {
return;
}
testBase.generateCurrentQueueName(methodName);
try {
testBase.beforTest();
} catch (AssumptionViolatedException ave) {
throw ave;
} catch (Exception e) {
throw new RuntimeException(e);
}
baseDir = "target/" + className + "/" + methodName;
Attribute.AttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
attributeMap.put(Context.OperatorContext.SPIN_MILLIS, 500);
attributeMap.put(Context.DAGContext.APPLICATION_PATH, baseDir);
context = mockOperatorContext(1, attributeMap);
operator = new JMSStringInputOperator();
operator.setConnectionFactoryBuilder(new JMSBase.ConnectionFactoryBuilder()
{
@Override
public ConnectionFactory buildConnectionFactory()
{
// Create the connection factory using the environment variable credential provider.
// Connections this factory creates can talk to the queues in us-east-1 region.
SQSConnectionFactory connectionFactory =
SQSConnectionFactory.builder()
.withRegion(Region.getRegion(Regions.US_EAST_1))
.withAWSCredentialsProvider(new PropertiesFileCredentialsProvider(testBase.getDevCredsFilePath()))
.build();
return connectionFactory;
}
@Override
public String toString()
{
return className + "/" + methodName + "/ConnectionFactoryBuilder";
}
});
operator.setSubject(testBase.getCurrentQueueName());
// for SQS ack mode should be "AUTO_ACKNOWLEDGE" and transacted = false
operator.setAckMode("AUTO_ACKNOWLEDGE");
operator.setTransacted(false);
sink = new CollectorTestSink<>();
operator.output.setSink(sink);
operator.setup(context);
operator.activate(context);
}
static String testName(Description description) {
return description.getClassName() + "." + description.getMethodName();
}
private String desc(Description description) {
return description.getClassName() + "." + description.getMethodName();
}
public ReportWriter getWriterForTest(final Description testDescription) {
return new JsonReportWriter(
outputDir, testDescription.getClassName(), testDescription.getMethodName());
}
@Override
protected void starting(Description description) {
super.starting(description);
className = description.getClassName();
memWatcher = new MemWatcher();
}
/**
* Determine whether this result holder already has the specified test.
* @param desc the description of th etest to look for.
* @return <code>true</code> if the test already exists, <code>false</code> otherwise.
*/
public boolean hasTest(final Description desc) {
final String name = desc.getClassName() + "." + desc.getMethodName();
return tests.contains(name);
}