private static boolean sameInstance(ITestResult configResult, Object instance) { return instance.equals(configResult.getInstance()); }
private static boolean sameInstance(ITestResult configResult, Object instance) { return instance.equals(configResult.getInstance()); }
private boolean isRelated(ITestResult result) { ITestNGMethod m = result.getMethod(); if (!m.isBeforeClassConfiguration() && !m.isBeforeMethodConfiguration()) { return false; } Object current = this.getInstance(); Object thatObject = result.getInstance(); return current.getClass().isAssignableFrom(thatObject.getClass()) || thatObject.getClass().isAssignableFrom(current.getClass()); }
/** * @return the test results that apply to one of the instances of the testMethod. */ private Set<ITestResult> keepSameInstances(ITestNGMethod method, Set<ITestResult> results) { Set<ITestResult> result = Sets.newHashSet(); for (ITestResult r : results) { Object o = method.getInstance(); // Keep this instance if 1) It's on a different class or 2) It's on the same class // and on the same instance Object instance = r.getInstance() != null ? r.getInstance() : r.getMethod().getInstance(); if (r.getTestClass() != method.getTestClass() || instance == o) result.add(r); } return result; }
Object instance = tr.getInstance(); pw.append("<td>").append(Objects.toString(instance)).append("</td>");
/** * Add the time of the configuration method to this test method. * * The only problem with this method is that the timing of a test method * might not be added to the time of the same configuration method that ran before * it but since they should all be equivalent, this should never be an issue. */ private long getNextConfiguration(ListMultiMap<Object, ITestResult> configurations, ITestResult tr) { long result = 0; List<ITestResult> confResults = configurations.get(tr.getInstance()); Map<ITestNGMethod, ITestResult> seen = Maps.newHashMap(); for (ITestResult r : confResults) { if (! seen.containsKey(r.getMethod())) { result += r.getEndMillis() - r.getStartMillis(); seen.put(r.getMethod(), r); } } confResults.removeAll(seen.values()); return result; }
/** @return the test results that apply to one of the instances of the testMethod. */ private Set<ITestResult> keepSameInstances(ITestNGMethod method, Set<ITestResult> results) { Set<ITestResult> result = Sets.newHashSet(); for (ITestResult r : results) { Object o = method.getInstance(); // Keep this instance if 1) It's on a different class or 2) It's on the same class // and on the same instance Object instance = r.getInstance() != null ? r.getInstance() : r.getMethod().getInstance(); if (r.getTestClass() != method.getTestClass() || instance == o) { result.add(r); } } return result; }
private void process(ITestResult result) { data.put(result.getInstance(), result.getFactoryParameters()); }
protected static void verifyInstanceNames(Map<String, List<ITestResult>> actual, String[] expected) { List<String> actualNames = Lists.newArrayList(); for (Map.Entry<String, List<ITestResult>> es : actual.entrySet()) { for (ITestResult tr : es.getValue()) { Object instance = tr.getInstance(); actualNames.add(es.getKey() + "#" + (instance != null ? instance.toString() : "")); } } Assert.assertEqualsNoOrder(actualNames.toArray(), expected); }
/** * Add the time of the configuration method to this test method. * * <p>The only problem with this method is that the timing of a test method might not be added to * the time of the same configuration method that ran before it but since they should all be * equivalent, this should never be an issue. */ private long getNextConfiguration( ListMultiMap<Object, ITestResult> configurations, ITestResult tr) { long result = 0; List<ITestResult> confResults = configurations.get(tr.getInstance()); Map<ITestNGMethod, ITestResult> seen = Maps.newHashMap(); for (ITestResult r : confResults) { if (!seen.containsKey(r.getMethod())) { result += r.getEndMillis() - r.getStartMillis(); seen.put(r.getMethod(), r); } } confResults.removeAll(seen.values()); return result; }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (!(skipConfiguration && method.isConfigurationMethod())) { invokedMethodNames.add(getName(testResult)); } testInstances.add(testResult.getInstance()); }
@Override public void onTestSkipped(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
private void handleInvocationResults(ITestNGMethod testMethod, ITestResult testResult, FailureContext failure, StatusHolder holder, boolean wasResultUnaltered) { // // Go through all the results and create a TestResult for each of them // List<ITestResult> resultsToRetry = Lists.newArrayList(); Throwable ite = testResult.getThrowable(); int status = computeTestStatusComparingTestResultAndStatusHolder(testResult, holder, wasResultUnaltered); boolean handled = holder.handled; IRetryAnalyzer retryAnalyzer = testMethod.getRetryAnalyzer(); boolean willRetry = retryAnalyzer != null && status == ITestResult.FAILURE && failure.instances != null && retryAnalyzer.retry(testResult); if (willRetry) { resultsToRetry.add(testResult); Object instance = testResult.getInstance(); if (!failure.instances.contains(instance)) { failure.instances.add(instance); } testResult.setStatus(ITestResult.SKIP); } else { testResult.setStatus(status); if (status == ITestResult.FAILURE && !handled) { handleException(ite, testMethod, testResult, failure.count++); } } }
@Override public void onTestSuccess(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
@Override public void onTestFailure(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
public void onConfigurationFailure(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
public void onConfigurationSuccess(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
public void onConfigurationSkip(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
private static void runTest(Class<?> cls, int n1, int n2) { TestNG tng = create(cls); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener(tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 2); Iterator<ITestResult> iterator = tla.getPassedTests().iterator(); BaseFactorySample t1 = (BaseFactorySample) iterator.next().getInstance(); BaseFactorySample t2 = (BaseFactorySample) iterator.next().getInstance(); Assert.assertEquals(t1.getN(), n1); Assert.assertEquals(t2.getN(), n2); } }
@Test public void factoriesShouldBeInvokedInTheOrderOfCreation() { TestNG tng = create(OrderFactory.class); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener(tla); tng.run(); List<ITestResult> passed = tla.getPassedTests(); for (int i = 0; i < passed.size(); i++) { Assert.assertEquals(((OrderSample) passed.get(i).getInstance()).getValue(), i); } } }