下面列出了org.junit.runner.Description#getMethodName() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** {@inheritDoc} */
@Override protected void failed(Throwable e, Description lastTest) {
try {
log().error("Last test failed [name=" + lastTest.getMethodName() +
", reason=" + e.getMessage() + "]. Restarting the grid.");
// Release the indexing.
if (barrier != null)
barrier.reset();
stopAllGrids();
beforeTestsStarted();
log().error("Grid restarted.");
}
catch (Exception restartFailure) {
throw new RuntimeException("Failed to recover after test failure [test=" + lastTest.getMethodName() +
", reason=" + e.getMessage() + "]. Subsequent test results of this test class are incorrect.",
restartFailure);
}
}
private void map(Description source, Description parent) {
for (Description child : source.getChildren()) {
Description mappedChild;
if (child.getMethodName() != null) {
mappedChild = Description.createSuiteDescription(String.format("%s [%s](%s)", child.getMethodName(), getDisplayName(), child.getClassName()));
parent.addChild(mappedChild);
if (!isTestEnabled(new TestDescriptionBackedTestDetails(source, child))) {
disabledTests.add(child);
} else {
enabledTests.add(child);
}
} else {
mappedChild = Description.createSuiteDescription(child.getClassName());
}
descriptionTranslations.put(child, mappedChild);
map(child, parent);
}
}
protected String expandResourcePath(Description description, String resourcePath) {
if (resourcePath.contains("/")) {
// already expanded path
return resourcePath;
}
else {
Class<?> testClass = description.getTestClass();
if (resourcePath.isEmpty()) {
// use test class and method name as resource file name
return testClass.getName().replace(".", "/") + "." + description.getMethodName() + "." + DMN_SUFFIX;
}
else {
// use test class location as resource location
return testClass.getPackage().getName().replace(".", "/") + "/" + resourcePath;
}
}
}
protected String expandResourcePath(Description description, String resourcePath) {
if (resourcePath.contains("/")) {
// already expanded path
return resourcePath;
}
else {
Class<?> testClass = description.getTestClass();
if (resourcePath.isEmpty()) {
// use test class and method name as resource file name
return testClass.getName().replace(".", "/") + "." + description.getMethodName() + "." + DMN_SUFFIX;
}
else {
// use test class location as resource location
return testClass.getPackage().getName().replace(".", "/") + "/" + resourcePath;
}
}
}
@Override
protected void starting(Description description) {
if(description.getAnnotation(BpmnModelResource.class) != null) {
Class<?> testClass = description.getTestClass();
String methodName = description.getMethodName();
String resourceFolderName = testClass.getName().replaceAll("\\.", "/");
String bpmnResourceName = resourceFolderName + "." + methodName + ".bpmn";
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(bpmnResourceName);
try {
bpmnModelInstance = Bpmn.readModelFromStream(resourceAsStream);
} finally {
IoUtil.closeSilently(resourceAsStream);
}
}
}
@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);
}
public void startFakeTestCase(Description description) {
String uid = getSuiteUid(description);
String name = description.isTest() ? description.getMethodName() : description.getClassName();
TestCaseStartedEvent event = new TestCaseStartedEvent(uid, name);
AnnotationManager am = new AnnotationManager(description.getAnnotations());
am.update(event);
fireClearStepStorage();
getLifecycle().fire(event);
}
@Override
protected void starting(Description description)
{
//lots of test case get around the normal workflow and directly write to file. So should disable bloom filter
DefaultBucket.setDisableBloomFilterByDefault(true);
TestUtils.deleteTargetTestClassFolder(description);
managedStateContext = new MockManagedStateContext(ManagedStateTestUtils.getOperatorContext(9));
applicationPath = "target/" + description.getClassName() + "/" + description.getMethodName();
((FileAccessFSImpl)managedStateContext.getFileAccess()).setBasePath(applicationPath + "/" + "bucket_data");
managedStateContext.getFileAccess().init();
defaultBucket = new Bucket.DefaultBucket(1);
managedStateContext.getBucketsFileSystem().setup(managedStateContext);
}
@Override
public void testStarted(Description description) {
String methodName = description.getMethodName();
KurentoTest.setTestMethodName(methodName);
log.debug("Starting test {}.{}", testClass.getName(), methodName);
invokeServices(ServiceMethod.START, TEST);
KurentoTest
.logMessage("| TEST STARTING: " + description.getClassName() + "." + methodName);
}
/**
* Process the specified test description.
* @param desc the test description.
*/
private void processDescription(final Description desc) {
final String name = desc.getClassName();
final String testName = name + "." + desc.getMethodName();
if (!classes.contains(name)) classes.add(name);
if (!tests.contains(testName)) tests.add(testName);
}
@Override
protected void starting(Description description)
{
targetDir = "target/" + description.getClassName() + "/" + description.getMethodName();
try {
fs = FileSystem.get(new URI(targetDir + "/WAL"), conf);
fs.delete(new Path(targetDir), true);
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
fsWAL = new FileSystemWAL();
fsWAL.setFilePath(targetDir + "/WAL");
}
private static String formatDescriptionName(Description description) {
String methodName = (description.getMethodName() == null) ? "" : description.getMethodName();
String className = (description.getClassName() == null) ? "" : description.getClassName();
if (methodName.trim().isEmpty() || className.trim().isEmpty()) {
return description.getDisplayName();
}
return String.format(TEST_NAME_FORMAT, className, methodName);
}
protected void before(Description description) throws IOException {
String testClass = description.getTestClass().getName();
String methodName = description.getMethodName();
String name = testClass + "." + methodName;
try {
restClient.superuserSetup();
superuserToken = restClient.management().token().get(superuserName, superuserPassword);
} catch (BadRequestException e) {
logger.warn("Error creating superuser, may already exist");
}
username = "user_" + name + UUIDUtils.newTimeUUID();
password = username;
orgName = "org_" + name + UUIDUtils.newTimeUUID();
appName = "app_" + name + UUIDUtils.newTimeUUID();
organization = restClient.management().orgs().post(
new Organization(orgName, username, username + "@usergrid.com", username, password, null));
restClient.management().token().get(username, password);
clientCredentials = restClient.management().orgs().org(orgName).credentials().get(Credentials.class);
//appCredentials = restClient.management().orgs().org(orgName).app().path//.credentials().get(Credentials.class);
ApiResponse appResponse = restClient.management().orgs()
.org(organization.getName()).app().post(new Application(appName));
appUuid = (String) appResponse.getEntities().get(0).get("uuid");
application = new Application(appResponse);
appCredentials = restClient.pathResource( "management/orgs/"+orgName+"/apps/"+appName+"/credentials" ).get( Credentials.class,true );
refreshIndex();
ApiResponse response = restClient.management().token().post(new Token(username, password));
refreshIndex();
}
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 static String getTestName(Description description) {
return description.getTestClass().getSimpleName() + SEPARATOR + description.getMethodName();
}
public ReportWriter getWriterForTest(final Description testDescription) {
return new JsonReportWriter(
outputDir, testDescription.getClassName(), testDescription.getMethodName());
}
@Override
public void testFailure(Failure failure) throws Exception {
Description description = failure.getDescription();
String key = description.getClassName() + "#" + description.getMethodName();
failedTests.put(key, AngelicExecution.previousValue);
}
private String getTestName(Description d) {
return d.getClassName() + "." + d.getMethodName();
}
/**
* Returns the name of a test to be logged.
*
* @param description
* the description, must not be {@code null}
* @return the description name, never {@code null}
*/
private String getDescriptionName(final Description description) {
return description.getClassName() + '.' + description.getMethodName();
}
/**
* Determines if the given {@link Description} is describing a test method.
*
* @param description
* the {@link Description} to check, must not be {@code null}
* @return whether the description is describing a test method
*/
public static boolean isTestMethod(final Description description) {
return description.getMethodName() != null;
}