1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
---
layout: default
class: Project
title: -testunresolved BOOLEAN
summary: Will execute a JUnit testcase ahead of any other test case that will abort if there are any unresolved bundles.
---
@Override
public boolean prepare() throws Exception {
if (!prepared) {
prepared = true;
super.prepare();
ProjectLauncher launcher = getProjectLauncher();
if (port > 0) {
launcher.getRunProperties().put(TESTER_PORT, "" + port);
if (host != null)
launcher.getRunProperties().put(TESTER_HOST, "" + host);
}
launcher.getRunProperties().put(TESTER_UNRESOLVED, project.getProperty(Constants.TESTUNRESOLVED, "true"));
launcher.getRunProperties().put(TESTER_DIR, getReportDir().getAbsolutePath());
launcher.getRunProperties().put(TESTER_CONTINUOUS, "" + getContinuous());
if (Processor.isTrue(project.getProperty(Constants.RUNTRACE)))
launcher.getRunProperties().put(TESTER_TRACE, "true");
try {
// use reflection to avoid NoSuchMethodError due to change in
// API
File cwd = (File) getClass().getMethod("getCwd").invoke(this);
if (cwd != null)
launcher.setCwd(cwd);
}
catch (NoSuchMethodException e) {
// ignore
}
Collection<String> testnames = getTests();
if (testnames.size() > 0) {
launcher.getRunProperties().put(TESTER_NAMES, Processor.join(testnames));
}
// This is only necessary because we might be picked
// as default and that implies we're not on the -testpath
launcher.addDefault(Constants.DEFAULT_TESTER_BSN);
launcher.prepare();
}
return true;
}
public void run() {
continuous = Boolean.valueOf(context.getProperty(TESTER_CONTINUOUS));
trace = context.getProperty(TESTER_TRACE) != null;
if (thread == null)
trace("running in main thread");
// We can be started on our own thread or from the main code
thread = Thread.currentThread();
String testcases = context.getProperty(TESTER_NAMES);
trace("test cases %s", testcases);
if (context.getProperty(TESTER_PORT) != null) {
port = Integer.parseInt(context.getProperty(TESTER_PORT));
try {
trace("using port %s", port);
jUnitEclipseReport = new JUnitEclipseReport(port);
}
catch (Exception e) {
System.err.println("Cannot create link Eclipse JUnit on port " + port);
System.exit(254);
}
}
//
// Jenkins does not detect test failures unless reported
// by JUnit XML output. If we have an unresolved failure
// we timeout. The following will test if there are any
// unresolveds and report this as a JUnit failure. It can
// be disabled with -testunresolved=false
//
String unresolved = context.getProperty(TESTER_UNRESOLVED);
trace("run unresolved %s", unresolved);
if (unresolved == null || unresolved.equalsIgnoreCase("true")) {
//
// Check if there are any unresolved bundles.
// If yes, we run a test case to get a proper JUnit report
//
for ( Bundle b : context.getBundles()) {
if ( b.getState() == Bundle.INSTALLED) {
//
// Now do it again but as a test case
// so we get a proper JUnit report
//
int err = test(context.getBundle(), "aQute.junit.UnresolvedTester", null);
if (err != 0)
System.exit(err);
}
}
}
if (testcases == null) {
// if ( !continuous) {
// System.err.println("\nThe -testcontinuous property must be set if invoked without arguments\n");
// System.exit(255);
// }
trace("automatic testing of all bundles with " + aQute.bnd.osgi.Constants.TESTCASES + " header");
try {
automatic();
}
catch (IOException e) {
// ignore
}
} else {
trace("receivednames of classes to test %s", testcases);
try {
int errors = test(null, testcases, null);
System.exit(errors);
}
catch (Exception e) {
e.printStackTrace();
System.exit(254);
}
}
}
|