/** * adds a test suite to this test suite */ @Override public void addTestSuite(Class<? extends TestCase> testClass) { if (ignoreRandomFailures() && testClass.isAnnotationPresent(RandomlyFails.class)) { System.err.println("Skipping " + testClass.getName()); return; } NbTest t = new NbTestSuite(testClass); t.setFilter(fFilter); addTest(t); }
/** * Constructs a TestSuite from the given class. Adds all the methods * starting with "test" as test cases to the suite. * */ public NbTestSuite(Class<? extends TestCase> theClass) { super(testCaseClassOrDummy(theClass)); } private static Class<? extends TestCase> testCaseClassOrDummy(Class<? extends TestCase> testClass) {
/** Factory method to create a special execution suite that not only * executes the tests but also measures the times each execution took. * It then compares the times and fails if the difference is too big. * Test tests can be executed more times to eliminate the effect * of GC and hotspot compiler. * * @param clazz the class to create tests for (from methods starting with test) * @param slowness this must be true: slowness * min < max * @param repeat number of times to repeat the test */ public static NbTestSuite speedSuite (Class<? extends TestCase> clazz, int slowness, int repeat) { if (ignoreRandomFailures()) { System.err.println("Skipping " + clazz.getName()); return new NbTestSuite("skipping"); } return new SpeedSuite (clazz, repeat, slowness, SpeedSuite.CONSTANT); }
testLoader.loadClass("junit.framework.Test"); testLoader.loadClass("org.netbeans.junit.NbTestSuite"); NbTestSuite toRun = new NbTestSuite(); if (item.fileNames == null) { MethodOrder.orderMethods(sndClazz, null); toRun.addTest(new NbTestSuiteLogCheck(sndClazz)); } else { NbTestSuite t = new NbTestSuiteLogCheck(); t.addTests(sndClazz, item.fileNames); toRun.addTest(t); toRun.addTest(sndClazz.newInstance()); toRun.addTest(handler); testCount = toRun.countTestCases(); toRun.run(result); } catch (ClassNotFoundException ex) { result.addError(this, ex);
public static TestSuite suite(Class<?> clazz, String filePattern) { NbTestSuite result = new NbTestSuite(); Pattern patt = Pattern.compile(filePattern); for (String test : listTests(clazz)) { if (!patt.matcher(test).matches()) { continue; } //TODO: URL testURL = clazz.getClassLoader().getResource(test); assertNotNull(testURL); FileObject testFO = URLMapper.findFileObject(testURL); assertNotNull(testFO); String hint = test.substring(0, test.length() - ".test".length()) + ".hint"; URL hintURL = clazz.getClassLoader().getResource(hint); assertNotNull(hintURL); FileObject hintFO = URLMapper.findFileObject(hintURL); assertNotNull(hintFO); try { for (TestCase tc : TestParser.parse(testFO.asText("UTF-8"))) { result.addTest(new DeclarativeHintsTestBase(hintFO, testFO, tc)); } } catch (IOException ex) { throw new IllegalStateException(ex); } } return result; }
void addTests(Class<? extends TestCase> clazz, String... names) throws Exception { Constructor cnt = clazz.getConstructor(String.class); for (String n : names) { Test t = (Test)cnt.newInstance(n); addTest(t); } }
private static Class<? extends TestCase> testCaseClassOrDummy(Class<? extends TestCase> testClass) { if (ignoreRandomFailures() && testClass.isAnnotationPresent(RandomlyFails.class)) { System.err.println("Skipping " + testClass.getName()); return APIJail.Dummy.class; } else { return testClass; } } private static class APIJail { // prevents Dummy from appearing as a public member
/** * Sets active filter. * @param filter Filter to be set as active for current test, null will reset filtering. */ public void setFilter(Filter filter) { Enumeration e; this.fFilter = filter; e = this.tests(); while(e.hasMoreElements()) { Object test = e.nextElement(); if (test instanceof NbTest) { //System.out.println("NbTestSuite.setFilter(): Setting filter:"+filter); ((NbTest)test).setFilter(filter); } } } /**
StringBuffer error = new StringBuffer (); for (int i = 0; i < repeat; i++) { super.run(result);
@Override public void runTest(Test test, TestResult result) { int e = result.errorCount(); int f = result.failureCount(); LOG.log(Level.FINE, "Running test {0}", test); super.runTest(test, result); LOG.log(Level.FINE, "Finished: {0}", test); if (e == result.errorCount() && f == result.failureCount()) { NbModuleLogHandler.checkFailures((TestCase) test, result, test instanceof NbTestCase ? ((NbTestCase) test).getWorkDirPath() : Manager.getWorkDirPath()); } } }
/** Factory method to create a special execution suite that not only * executes the tests but also measures the times each execution took. * It then compares the times devided by the size of query * and fails if the difference is too big. * Test tests can be executed more times to eliminate the effect * of GC and hotspot compiler. * * @param clazz the class to create tests for (from methods starting with test) * @param slowness this must be true: slowness * min < max * @param repeat number of times to repeat the test */ public static NbTestSuite linearSpeedSuite (Class<? extends TestCase> clazz, int slowness, int repeat) { if (ignoreRandomFailures()) { System.err.println("Skipping " + clazz.getName()); return new NbTestSuite("skipping"); } return new SpeedSuite (clazz, repeat, slowness, SpeedSuite.LINEAR); }
/** * Checks if a test isn't filtered out by the active filter. * @return true if the test can run */ public @Override boolean canRun() { if (NbTestSuite.ignoreRandomFailures()) { if (getClass().isAnnotationPresent(RandomlyFails.class)) { System.err.println("Skipping " + getClass().getName()); return false; } try { if (getClass().getMethod(getName()).isAnnotationPresent(RandomlyFails.class)) { System.err.println("Skipping " + getClass().getName() + "." + getName()); return false; } } catch (NoSuchMethodException x) { // Specially named methods; let it pass. } } if (null == filter) { //System.out.println("NBTestCase.canRun(): filter == null name=" + name ()); return true; // no filter was aplied } boolean isIncluded = filter.isIncluded(this.getName()); //System.out.println("NbTestCase.canRun(): filter.isIncluded(this.getName())="+isIncluded+" ; this="+this); return isIncluded; }