Skip to content
Permalink
Browse files

Merge branch 'master' of https://github.com/cbeust/testng.git

  • Loading branch information...
lukasj committed Feb 6, 2012
2 parents 77de21b + 1bd2782 commit efa11aacf9a1b0bddd4dc96addfa898cbc816132
@@ -3,12 +3,18 @@ Current

Added: @DataProvider(indices) to return specific indices of a data provider
Added: New HTML reports
Added: configfailurepolicy=continue with DataProviders (toddq)
Added: ITestResult#getTestContext (bpedman)
Fixed: invocationCount > 1 + timeOut wasn't timing out properly
Fixed: When running TestNG programmatically, child xml suites are not run (when added using setSuiteFIles()) (Gaurav Gupta)
Fixed: GITHUB-145: Excessive test method execution (githubCast)
Fixed: GITHUB-149: reversed arguments in failAssertEqualsNoOrder().
Fixed: EmailableReporter: methods are now *really* sorted chronologically.

Eclipse:

Added: You can now add the testng.jar sources as a library (Nick Tan)
Added: Upgraded the plug-in to 3.4+ (Nick Tan)
Added: dependsOnGroups now fully supported
Fixed: @Parameters now works with both ("foo") and ({"foo"}) (davekerber)

@@ -2,7 +2,7 @@
# TestNG distribution
#
testng.basename=testng
testng.version=6.3.2beta
testng.version=6.4beta
testng.fullname=${testng.basename}-${testng.version}

#
@@ -322,6 +322,11 @@

<delete file="${jdk15.jar}" />
<copy file="${testng.jar}" tofile="${jdk15.jar}" />

<!-- sources -->
<property name="sources" value="${testng-eclipse.dir}/lib/testng-sources.jar"/>
<echo>Sources: ${sources}</echo>
<jar destfile="${sources}" basedir="src/main/java/" />
</target>

<target name="ftp">
@@ -43,7 +43,7 @@ <h3>Asserts</h3>

<h3>Related reading</h3>

<a href="http://www.opengamma.com/blog/2011/converting-opengamma-junit-testng">Here is the detailed report of a company that successfully converted a large codebase of JUnit 4 tests over to TestNG</a>.
<a href="http://www.opengamma.com/blog/2011/04/04/converting-opengamma-junit-testng">Here is the detailed report of a company that successfully converted a large codebase of JUnit 4 tests over to TestNG</a>.

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
@@ -89,4 +89,9 @@
public String getTestName();

public String getInstanceName();

/**
* @return the {@link ITestContext} for this test result.
*/
public ITestContext getTestContext();
}
@@ -265,6 +265,32 @@ public void initializeSuitesAndJarFile() {
// The Eclipse plug-in (RemoteTestNG) might have invoked this method already
// so don't initialize suites twice.
if (m_suites.size() > 0) {
//to parse the suite files (<suite-file>), if any
for (XmlSuite s: m_suites){
List<String> suiteFiles = s.getSuiteFiles();
for (int i = 0; i < suiteFiles.size(); i++) {
try {
Collection<XmlSuite> childSuites = getParser(suiteFiles.get(i)).parse();
for (XmlSuite cSuite : childSuites){
cSuite.setParentSuite(s);
s.getChildSuites().add(cSuite);
}
}
catch(FileNotFoundException e) {
e.printStackTrace(System.out);
}
catch (ParserConfigurationException e) {
e.printStackTrace(System.out);
} catch (SAXException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}


}

}
return;
}

@@ -98,7 +98,7 @@ private void setMethodInvocationFailure(ITestNGMethod method, Object instance) {
instances = Sets.newHashSet();
m_methodInvocationResults.put(method, instances);
}
instances.add(instance);
instances.add(getMethodInvocationToken(method, instance));
}

public Invoker(IConfiguration configuration,
@@ -166,7 +166,8 @@ private void invokeConfigurations(IClass testClass,
tm,
null,
System.currentTimeMillis(),
System.currentTimeMillis());
System.currentTimeMillis(),
m_testContext);

IConfigurationAnnotation configurationAnnotation= null;
try {
@@ -450,7 +451,7 @@ private boolean confInvocationPassed(ITestNGMethod method, ITestNGMethod current
else if (m_continueOnFailedConfiguration &&
currentTestMethod != null &&
m_methodInvocationResults.containsKey(currentTestMethod)) {
result = !m_methodInvocationResults.get(currentTestMethod).contains(instance);
result = !m_methodInvocationResults.get(currentTestMethod).contains(getMethodInvocationToken(currentTestMethod, instance));
}
else if (! m_continueOnFailedConfiguration) {
for(Class<?> clazz: m_classInvocationResults.keySet()) {
@@ -476,6 +477,12 @@ else if (! m_continueOnFailedConfiguration) {
return result;
}

// Creates a token for tracking a unique invocation of a method on an instance.
// Is used when configFailurePolicy=continue.
private Object getMethodInvocationToken(ITestNGMethod method, Object instance) {
return String.format("%s+%d", instance.toString(), method.getCurrentInvocationCount());
}

/**
* Effectively invokes a configuration method on all passed in instances.
* TODO: Should change this method to be more like invokeMethod() so that we can
@@ -643,7 +650,8 @@ private ITestResult invokeMethod(Object[] instances,
tm,
null,
System.currentTimeMillis(),
0);
0,
m_testContext);
testResult.setParameters(parameterValues);
testResult.setHost(m_testContext.getHost());
testResult.setStatus(ITestResult.STARTED);
@@ -1127,7 +1135,8 @@ private ParameterBag createParameters(ITestNGMethod testMethod,
testMethod,
null /* cause */,
start,
System.currentTimeMillis());
System.currentTimeMillis(),
m_testContext);
String missingGroup = testMethod.getMissingGroup();
if (missingGroup != null) {
testResult.setThrowable(new Throwable("Method " + testMethod
@@ -1263,7 +1272,8 @@ private ParameterBag createParameters(ITestNGMethod testMethod,
testMethod,
cause,
start,
System.currentTimeMillis());
System.currentTimeMillis(),
m_testContext);
r.setStatus(TestResult.FAILURE);
result.add(r);
runTestListeners(r);
@@ -1284,7 +1294,8 @@ private ITestResult registerSkippedTestResult(ITestNGMethod testMethod, Object i
testMethod,
throwable,
start,
System.currentTimeMillis());
System.currentTimeMillis(),
m_testContext);
result.setStatus(TestResult.SKIP);
runTestListeners(result);

@@ -1380,7 +1391,8 @@ private ParameterBag handleParameters(ITestNGMethod testMethod,
testMethod,
cause,
System.currentTimeMillis(),
System.currentTimeMillis()));
System.currentTimeMillis(),
m_testContext));
}
}

@@ -122,7 +122,8 @@ public long getMaxTimeOut() {
m_testMethod,
null,
start,
System.currentTimeMillis());
System.currentTimeMillis(),
m_testContext);
r.setStatus(TestResult.SKIP);
m_testResults.add(r);
m_invoker.runTestListeners(r);
@@ -3,6 +3,7 @@
import org.testng.IAttributes;
import org.testng.IClass;
import org.testng.ITest;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.Reporter;
@@ -30,6 +31,7 @@
transient private Object[] m_parameters = {};
transient private Object m_instance;
private String m_instanceName;
private ITestContext m_context;

public TestResult() {

@@ -40,9 +42,10 @@ public TestResult(IClass testClass,
ITestNGMethod method,
Throwable throwable,
long start,
long end)
long end,
ITestContext context)
{
init(testClass, instance, method, throwable, start, end);
init(testClass, instance, method, throwable, start, end, context);
}

/**
@@ -59,7 +62,8 @@ public void init (IClass testClass,
ITestNGMethod method,
Throwable throwable,
long start,
long end)
long end,
ITestContext context)
{
m_testClass = testClass;
m_throwable = throwable;
@@ -70,6 +74,7 @@ public void init (IClass testClass,
m_startMillis = start;
m_endMillis = end;
m_method = method;
m_context = context;

m_instance = instance;

@@ -282,6 +287,14 @@ public void setAttribute(String name, Object value) {
public Object removeAttribute(String name) {
return m_attributes.removeAttribute(name);
}

public ITestContext getTestContext() {
return m_context;
}

public void setContext(ITestContext context) {
m_context = context;
}

@Override
public int compareTo(ITestResult comparison) {
@@ -4,10 +4,10 @@
import org.testng.internal.Utils;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -40,7 +40,7 @@ public static final void execute(List<? extends Runnable> tasks, int threadPoolS
final CountDownLatch startGate= new CountDownLatch(1);
final CountDownLatch endGate= new CountDownLatch(tasks.size());
Utils.log("TestRunner", 2, "Starting executor timeOut:" + timeout + "ms"
Utils.log("ThreadUtil", 2, "Starting executor timeOut:" + timeout + "ms"
+ " workers:" + tasks.size() + " threadPoolSize:" + threadPoolSize);
ExecutorService pooledExecutor = // Executors.newFixedThreadPool(threadPoolSize);
new ThreadPoolExecutor(threadPoolSize, threadPoolSize,
@@ -55,24 +55,50 @@ public Thread newThread(Runnable r) {
}
});
for(final Runnable task: tasks) {
try {
pooledExecutor.execute(new CountDownLatchedRunnable(task,
endGate, triggerAtOnce ? null : startGate));
}
catch(RejectedExecutionException reex) {
; // this should never happen as we submit all tasks at once
}
List<Callable<Object>> callables = Lists.newArrayList();
for (final Runnable task : tasks) {
callables.add(new Callable<Object>() {
@Override
public Object call() throws Exception {
task.run();
return null;
}
});
}
try {
startGate.countDown();
endGate.await();
pooledExecutor.shutdown();
}
catch(InterruptedException e) {
Thread.currentThread().interrupt();
log(2, "Error waiting for concurrent executors to finish " + e.getMessage());
if (timeout != 0) {
pooledExecutor.invokeAll(callables, timeout, TimeUnit.MILLISECONDS);
} else {
pooledExecutor.invokeAll(callables);
}
} catch (InterruptedException e1) {
e1.printStackTrace();
}
// for(final Runnable task: tasks) {
// try {
// pooledExecutor.execute(new CountDownLatchedRunnable(task,
// endGate, triggerAtOnce ? null : startGate));
// pooledExecutor.awaitTermination(timeout, TimeUnit.MILLISECONDS);
// }
// catch(RejectedExecutionException reex) {
// reex.printStackTrace();
// ; // this should never happen as we submit all tasks at once
// }
// catch(Exception ex) {
// ex.printStackTrace();
// }
// }
// try {
// startGate.countDown();
// endGate.await();
// pooledExecutor.shutdown();
// }
// catch(InterruptedException e) {
// Thread.currentThread().interrupt();
// log(2, "Error waiting for concurrent executors to finish " + e.getMessage());
// }
}
/**
@@ -122,7 +122,8 @@ public void setInvokedMethodListeners(List<IInvokedMethodListener> listeners) {
tm,
tri.m_failure,
tri.m_start,
Calendar.getInstance().getTimeInMillis());
Calendar.getInstance().getTimeInMillis(),
null);

if(tri.isFailure()) {
tr.setStatus(ITestResult.FAILURE);
@@ -0,0 +1,31 @@
package test.configurationfailurepolicy;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ClassWithFailedBeforeMethodAndMultipleInvocations {

@BeforeMethod
public void setupShouldFail() {
throw new RuntimeException("Failing in setUp");
}

@DataProvider( name = "data.provider" )
public Object[][] dataProvider() {
return new Object[][] {
new Object[] { "data1" },
new Object[] { "data2" }
};
}

@Test( dataProvider = "data.provider" )
public void test1( String s ) {

}

@Test( invocationCount = 2 )
public void test2() {

}
}
@@ -0,0 +1,13 @@
package test.configurationfailurepolicy;

import org.testng.annotations.Factory;

public class FactoryClassWithFailedBeforeMethodAndMultipleInvocations extends ClassWithFailedBeforeMethodAndMultipleInvocations {
@Factory
public Object[] createTests() {
Object[] instances = new Object[2];
instances[0] = new FactoryClassWithFailedBeforeMethodAndMultipleInvocations();
instances[1] = new FactoryClassWithFailedBeforeMethodAndMultipleInvocations();
return instances;
}
}

0 comments on commit efa11aa

Please sign in to comment.
You can’t perform that action at this time.