use of org.testng.ITestClass in project arrow by NetEase.
the class NeXMLSuiteResultWriter method addTestResult.
private void addTestResult(XMLStringBuffer xmlBuffer, ITestResult testResult) {
Properties attribs = getTestResultAttributes(testResult);
attribs.setProperty(NeXMLReporterConfig.ATTR_STATUS, getStatusString(testResult.getStatus()));
ITestNGMethod method = testResult.getMethod();
ITestClass testClass = method.getTestClass();
String authors = this.getAuthors(testClass.getName(), method);
String tcCase = this.getTestMethodAttr(NeXMLReporterConfig.ATTR_TC_NAME, testClass.getName(), method);
String suites = this.getTestMethodAttr(NeXMLReporterConfig.ATTR_TC_SUITES, testClass.getName(), method);
attribs.setProperty(NeXMLReporterConfig.ATTR_AUTHOR, authors);
attribs.setProperty(NeXMLReporterConfig.ATTR_TC_NAME, tcCase);
attribs.setProperty(NeXMLReporterConfig.ATTR_TC_SUITES, suites);
xmlBuffer.push(NeXMLReporterConfig.TAG_TEST_METHOD, attribs);
addTestMethodParams(xmlBuffer, testResult);
addTestResultException(xmlBuffer, testResult);
addTestResultOutput(xmlBuffer, testResult);
if (config.isGenerateTestResultAttributes()) {
addTestResultAttributes(xmlBuffer, testResult);
}
xmlBuffer.pop();
}
use of org.testng.ITestClass in project arrow by NetEase.
the class PowerEmailableReporter method resultSummary.
/**
* @param tests
*/
private void resultSummary(ISuite suite, IResultMap tests, String testname, String style, String details) {
if (tests.getAllResults().size() > 0) {
StringBuffer buff = new StringBuffer();
String lastClassName = "";
int mq = 0;
int cq = 0;
Map<String, Integer> methods = new HashMap<String, Integer>();
Set<String> setMethods = new HashSet<String>();
for (ITestNGMethod method : getMethodSet(tests, suite)) {
m_row += 1;
ITestClass testClass = method.getTestClass();
String className = testClass.getName();
if (mq == 0) {
String id = (m_testIndex == null ? null : "t" + Integer.toString(m_testIndex));
titleRow(testname + " — " + style + details, 5, id);
m_testIndex = null;
}
if (!className.equalsIgnoreCase(lastClassName)) {
if (mq > 0) {
cq += 1;
m_out.print("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td");
if (mq > 1) {
m_out.print(" rowspan=\"" + mq + "\"");
}
m_out.println(">" + lastClassName + "</td>" + buff);
}
mq = 0;
buff.setLength(0);
lastClassName = className;
}
Set<ITestResult> resultSet = tests.getResults(method);
long end = Long.MIN_VALUE;
long start = Long.MAX_VALUE;
for (ITestResult testResult : tests.getResults(method)) {
if (testResult.getEndMillis() > end) {
end = testResult.getEndMillis();
}
if (testResult.getStartMillis() < start) {
start = testResult.getStartMillis();
}
}
mq += 1;
if (mq > 1) {
buff.append("<tr class=\"" + style + (cq % 2 == 0 ? "odd" : "even") + "\">");
}
String description = method.getDescription();
String testInstanceName = resultSet.toArray(new ITestResult[] {})[0].getTestName();
// Calculate each test run times, the result shown in the html report.
ITestResult[] results = resultSet.toArray(new ITestResult[] {});
String methodName = method.getMethodName();
if (setMethods.contains(methodName)) {
methods.put(methodName, methods.get(methodName) + 1);
} else {
setMethods.add(methodName);
methods.put(methodName, 0);
}
String parameterString = "";
int count = 0;
ITestResult result = null;
if (results.length > methods.get(methodName)) {
result = results[methods.get(methodName)];
int testId = getId(result);
for (Integer id : allRunTestIds) {
if (id.intValue() == testId)
count++;
}
Object[] parameters = result.getParameters();
boolean hasParameters = parameters != null && parameters.length > 0;
if (hasParameters) {
for (Object p : parameters) {
String pString = "null";
if (p != null) {
pString = p.toString();
}
parameterString = parameterString + Utils.escapeHtml(pString) + " ";
}
}
}
int methodId = method.getTestClass().getName().hashCode();
methodId = methodId + method.getMethodName().hashCode();
if (result != null)
methodId = methodId + (result.getParameters() != null ? Arrays.hashCode(result.getParameters()) : 0);
buff.append("<td><a href=\"#m" + methodId + "\">" + qualifiedName(method) + " " + (description != null && description.length() > 0 ? "(\"" + description + "\")" : "") + "</a>" + (null == testInstanceName ? "" : "<br>(" + testInstanceName + ")") + "</td><td>" + this.getAuthors(className, method) + "</td><td class=\"numi\">" + resultSet.size() + "</td>" + "<td>" + (count == 0 ? "" : count) + "</td>" + "<td>" + parameterString + "</td>" + "<td>" + start + "</td>" + "<td class=\"numi\">" + (end - start) + "</td>" + "</tr>");
}
if (mq > 0) {
cq += 1;
m_out.print("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td");
if (mq > 1) {
m_out.print(" rowspan=\"" + mq + "\"");
}
m_out.println(">" + lastClassName + "</td>" + buff);
}
}
}
use of org.testng.ITestClass in project gradle by gradle.
the class TestNGTestResultProcessorAdapter method onConfigurationFailure.
@Override
public void onConfigurationFailure(ITestResult testResult) {
ITestNGMethod testMethod = testResult.getMethod();
ITestClass testClass = testMethod.getTestClass();
TestClassInfo classInfo;
synchronized (lock) {
if (!failedConfigurations.add(testResult)) {
// workaround for bug in TestNG 6.2 (apparently fixed in some 6.3.x): listener is notified twice per event
return;
}
classInfo = this.testClassInfo.get(testClass);
}
// Synthesise a test for the broken configuration method
TestDescriptorInternal test = new DefaultTestMethodDescriptor(idGenerator.generateId(), testClass.getName(), testMethod.getMethodName());
Object parentId = classInfo == null ? null : classInfo.id;
resultProcessor.started(test, new TestStartEvent(testResult.getStartMillis(), parentId));
resultProcessor.failure(test.getId(), testResult.getThrowable());
resultProcessor.completed(test.getId(), new TestCompleteEvent(testResult.getEndMillis(), TestResult.ResultType.FAILURE));
}
use of org.testng.ITestClass in project sonar-java by SonarSource.
the class TestNGListenerTest method mockTestResult.
private ITestResult mockTestResult() {
ITestResult testResult = mock(ITestResult.class);
ITestClass testClass = mock(ITestClass.class);
when(testResult.getTestClass()).thenReturn(testClass);
ITestNGMethod testMethod = mock(ITestNGMethod.class);
when(testResult.getMethod()).thenReturn(testMethod);
when(testClass.getName()).thenReturn("class");
when(testMethod.getMethodName()).thenReturn("method");
return testResult;
}
Aggregations