use of junit.framework.TestCase in project kotlin by JetBrains.
the class CodegenTestsOnAndroidRunner method parseSingleReportInFolder.
private static List<TestCase> parseSingleReportInFolder(String reportFolder) throws IOException, SAXException, ParserConfigurationException {
File folder = new File(reportFolder);
File[] files = folder.listFiles();
assert files != null;
assert files.length == 1;
File reportFile = files[0];
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(reportFile);
Element root = doc.getDocumentElement();
NodeList testCases = root.getElementsByTagName("testcase");
List<TestCase> result = new ArrayList(testCases.getLength());
for (int i = 0; i < testCases.getLength(); i++) {
Element item = (Element) testCases.item(i);
final NodeList failure = item.getElementsByTagName("failure");
String name = item.getAttribute("name");
String clazz = item.getAttribute("classname");
if (failure.getLength() == 0) {
result.add(new TestCase(name) {
@Override
protected void runTest() throws Throwable {
}
});
} else {
result.add(new TestCase(name) {
@Override
protected void runTest() throws Throwable {
Assert.fail(failure.item(0).getTextContent());
}
});
}
}
return result;
}
use of junit.framework.TestCase in project kotlin by JetBrains.
the class CodegenTestsOnAndroidRunner method generateTestSuite.
private TestSuite generateTestSuite() {
TestSuite suite = new TestSuite("MySuite");
String resultOutput = runTests();
String reportFolder = pathManager.getTmpFolder() + "/build/outputs/androidTest-results/connected";
try {
List<TestCase> testCases = parseSingleReportInFolder(reportFolder);
for (TestCase aCase : testCases) {
suite.addTest(aCase);
}
Assert.assertNotEquals("There is no test results in report", 0, testCases.size());
} catch (Exception e) {
throw new RuntimeException("Can't parse test results in " + reportFolder + "\n" + resultOutput);
}
return suite;
}
use of junit.framework.TestCase in project jena by apache.
the class TestFactoryTDB method makeTest.
@Override
protected Test makeTest(Resource manifest, Resource entry, String testName, Resource action, Resource result) {
if (testRootName != null)
testName = testRootName + testName;
TestItem testItem = TestItem.create(entry, null);
TestCase test = null;
if (testItem.getTestType() != null) {
if (testItem.getTestType().equals(TestManifestX.TestQuery))
test = new QueryTestTDB(testName, report, testItem);
if (testItem.getTestType().equals(TestManifestX.TestSurpressed))
test = new SurpressedTest(testName, report, testItem);
if (test == null)
System.err.println("Unrecognized test type: " + testItem.getTestType());
}
// Default
if (test == null)
test = new QueryTestTDB(testName, report, testItem);
return test;
}
use of junit.framework.TestCase in project jmeter by apache.
the class JUnitSampler method sample.
/** {@inheritDoc} */
@Override
public SampleResult sample(Entry entry) {
if (getCreateOneInstancePerSample()) {
initializeTestObject();
}
SampleResult sresult = new SampleResult();
// Bug 41522 - don't use rlabel here
sresult.setSampleLabel(getName());
sresult.setSamplerData(className + "." + methodName);
sresult.setDataType(SampleResult.TEXT);
// Assume success
sresult.setSuccessful(true);
sresult.setResponseMessage(getSuccess());
sresult.setResponseCode(getSuccessCode());
if (this.testCase != null) {
// create a new TestResult
TestResult tr = new TestResult();
final TestCase theClazz = this.testCase;
try {
if (setUpMethod != null) {
setUpMethod.invoke(this.testObject, new Object[0]);
}
sresult.sampleStart();
tr.startTest(this.testCase);
// Do not use TestCase.run(TestResult) method, since it will
// call setUp and tearDown. Doing that will result in calling
// the setUp and tearDown method twice and the elapsed time
// will include setup and teardown.
tr.runProtected(theClazz, protectable);
tr.endTest(this.testCase);
sresult.sampleEnd();
if (tearDownMethod != null) {
tearDownMethod.invoke(testObject, new Object[0]);
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof AssertionFailedError) {
tr.addFailure(theClazz, (AssertionFailedError) cause);
} else if (cause instanceof AssertionError) {
// Convert JUnit4 failure to Junit3 style
AssertionFailedError afe = new AssertionFailedError(cause.toString());
// copy the original stack trace
afe.setStackTrace(cause.getStackTrace());
tr.addFailure(theClazz, afe);
} else if (cause != null) {
tr.addError(theClazz, cause);
} else {
tr.addError(theClazz, e);
}
} catch (IllegalAccessException | IllegalArgumentException e) {
tr.addError(theClazz, e);
}
if (!tr.wasSuccessful()) {
sresult.setSuccessful(false);
StringBuilder buf = new StringBuilder();
StringBuilder buftrace = new StringBuilder();
Enumeration<TestFailure> en;
if (getAppendError()) {
en = tr.failures();
if (en.hasMoreElements()) {
sresult.setResponseCode(getFailureCode());
buf.append(getFailure());
buf.append("\n");
}
while (en.hasMoreElements()) {
TestFailure item = en.nextElement();
buf.append("Failure -- ");
buf.append(item.toString());
buf.append("\n");
buftrace.append("Failure -- ");
buftrace.append(item.toString());
buftrace.append("\n");
buftrace.append("Trace -- ");
buftrace.append(item.trace());
}
en = tr.errors();
if (en.hasMoreElements()) {
sresult.setResponseCode(getErrorCode());
buf.append(getError());
buf.append("\n");
}
while (en.hasMoreElements()) {
TestFailure item = en.nextElement();
buf.append("Error -- ");
buf.append(item.toString());
buf.append("\n");
buftrace.append("Error -- ");
buftrace.append(item.toString());
buftrace.append("\n");
buftrace.append("Trace -- ");
buftrace.append(item.trace());
}
}
sresult.setResponseMessage(buf.toString());
sresult.setResponseData(buftrace.toString(), null);
}
} else {
// we should log a warning, but allow the test to keep running
sresult.setSuccessful(false);
// this should be externalized to the properties
sresult.setResponseMessage("Failed to create an instance of the class:" + getClassname() + ", reasons may be missing both empty constructor and one " + "String constructor or failure to instantiate constructor," + " check warning messages in jmeter log file");
sresult.setResponseCode(getErrorCode());
}
return sresult;
}
use of junit.framework.TestCase in project jena by apache.
the class QueryTestSDBFactory method makeTest.
@Override
public Test makeTest(Resource manifest, Resource entry, String testName, Resource action, Resource result) {
// Defaults.
Syntax querySyntax = getQuerySyntax(manifest);
if (testRootName != null)
testName = testRootName + testName;
if (querySyntax != null) {
if (!querySyntax.equals(Syntax.syntaxARQ) && !querySyntax.equals(Syntax.syntaxSPARQL))
throw new QueryTestException("Unknown syntax: " + querySyntax);
}
TestItem testItem = TestItem.create(entry, TestManifestX.TestQuery);
TestCase test = null;
if (testItem.getTestType().equals(TestManifestX.TestQuery))
test = new QueryTestSDB(storeDesc, testName, results, testItem);
if (testItem.getTestType().equals(TestManifestX.TestSurpressed))
test = new SurpressedTest(testName, results, testItem);
if (test == null)
System.err.println("Unrecognized test type: " + testItem.getTestType());
Resource action2 = testItem.getAction();
if (action2.hasProperty(TestManifestX.option))
System.out.println("OPTION");
return test;
}
Aggregations