Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Parallel test mode can now be specified from XML: <suite parallel="te…

…sts">
  • Loading branch information...
commit 4b9824b5e971a03fe42236402046147699375e3f 1 parent a1d43ef
cbeust authored
View
1  CHANGES.txt
@@ -6,6 +6,7 @@ TODO
===========================================================================
5.2
+Added: parallel can now be "methods" or "tests". Boolean version deprecated
Added: TestNGAntTask now uses the @ syntax to invoke TestNG
Added: Command line understands @ syntax
Added: JUnitConverter uses the new syntax
View
2  src/main/org/testng/ISuite.java
@@ -31,7 +31,7 @@
/**
* @return true if the tests must be run in parallel.
*/
- public boolean isParallel();
+ public String getParallel();
/**
* @return The value of this parameter, or null if none was specified.
View
6 src/main/org/testng/SuiteRunner.java
@@ -135,8 +135,8 @@ protected ITestRunnerFactory buildRunnerFactory(List testListeners) {
return factory;
}
- public boolean isParallel() {
- return m_suite.isParallel();
+ public String getParallel() {
+ return m_suite.getParallel();
}
public void run() {
@@ -233,7 +233,7 @@ private void privateRun() {
//
// Run all the test runners
//
- boolean testsInParallel = false; // Need config
+ boolean testsInParallel = XmlSuite.PARALLEL_TESTS.equals(m_suite.getParallel());
if (!testsInParallel) {
runSequentially();
}
View
7 src/main/org/testng/TestNG.java
@@ -337,14 +337,13 @@ public void setTestJar(String jarPath) {
public void setThreadCount(int threadCount) {
for (XmlSuite s : m_cmdlineSuite) {
s.setThreadCount(threadCount);
- s.setParallel(true);
}
}
/**
* Define whether this run will be run in parallel mode.
*/
- public void setParallel(boolean parallel) {
+ public void setParallel(String parallel) {
for (XmlSuite s : m_cmdlineSuite) {
s.setParallel(parallel);
}
@@ -754,7 +753,7 @@ private static void log(String string) {
tmpSuite.setAnnotations(suite.getAnnotations());
tmpSuite.setJUnit(suite.isJUnit());
tmpSuite.setName("Temporary suite for " + test.getName());
- tmpSuite.setParallel(suite.isParallel());
+ tmpSuite.setParallel(suite.getParallel());
tmpSuite.setParameters(suite.getParameters());
tmpSuite.setThreadCount(suite.getThreadCount());
tmpSuite.setVerbose(suite.getVerbose());
@@ -767,7 +766,7 @@ private static void log(String string) {
tmpTest.setJUnit(test.isJUnit());
tmpTest.setMethodSelectors(test.getMethodSelectors());
tmpTest.setName(test.getName());
- tmpTest.setParallel(test.isParallel());
+ tmpTest.setParallel(test.getParallel());
tmpTest.setParameters(test.getParameters());
tmpTest.setVerbose(test.getVerbose());
tmpTest.setXmlClasses(test.getXmlClasses());
View
10 src/main/org/testng/TestRunner.java
@@ -35,6 +35,7 @@
import org.testng.junit.JUnitMethodFinder;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlPackage;
+import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
/**
@@ -174,8 +175,8 @@ private void init(ISuite suite,
setVerbose(test.getVerbose());
- if (suite.isParallel()) {
- log(3, "Running the tests in parallel");
+ if (suite.getParallel() != null) {
+ log(3, "Running the tests in parallel mode:" + suite.getParallel());
}
setOutputDirectory(outputDirectory);
@@ -657,7 +658,10 @@ public void privateRun(XmlTest xmlTest) {
//
// Invoke the workers
//
- if (xmlTest.isParallel()) {
+ String parallelMode = xmlTest.getParallel();
+ if (XmlSuite.PARALLEL_METHODS.equals(parallelMode) ||
+ "true".equalsIgnoreCase(parallelMode))
+ {
//
// Parallel run
View
2  src/main/org/testng/reporters/FailedReporter.java
@@ -166,7 +166,7 @@ private void createXmlTest(ITestContext context, List<ITestNGMethod> methods, Xm
xmlTest.setBeanShellExpression(srcXmlTest.getExpression());
xmlTest.setIncludedGroups(srcXmlTest.getIncludedGroups());
xmlTest.setExcludedGroups(srcXmlTest.getExcludedGroups());
- xmlTest.setParallel(srcXmlTest.isParallel());
+ xmlTest.setParallel(srcXmlTest.getParallel());
xmlTest.setParameters(srcXmlTest.getParameters());
List<XmlClass> xmlClasses = createXmlClasses(methods);
xmlTest.setXmlClasses(xmlClasses);
View
4 src/main/org/testng/xml/TestNGContentHandler.java
@@ -109,7 +109,7 @@ private void xmlSuite(boolean start, Attributes attributes) {
}
String parallel = attributes.getValue("parallel");
if (null != parallel) {
- m_currentSuite.setParallel(new Boolean(parallel).booleanValue());
+ m_currentSuite.setParallel(parallel);
}
String threadCount = attributes.getValue("thread-count");
if (null != threadCount) {
@@ -189,7 +189,7 @@ private void xmlTest(boolean start, Attributes attributes) {
}
String parallel = attributes.getValue("parallel");
if (null != parallel) {
- m_currentTest.setParallel(new Boolean(parallel).booleanValue());
+ m_currentTest.setParallel(parallel);
}
String annotations = attributes.getValue("annotations");
if (null != annotations) {
View
20 src/main/org/testng/xml/XmlSuite.java
@@ -31,6 +31,10 @@
/** The JavaDoc annotation type ID ("javadoc"). */
public static final String JAVADOC_ANNOTATION_TYPE = TestNG.JAVADOC_ANNOTATION_TYPE;
+ /** Parallel modes */
+ public static final String PARALLEL_TESTS = "tests";
+ public static final String PARALLEL_METHODS = "methods";
+
private String m_test;
/** The suite name. */
@@ -39,7 +43,7 @@
/** The suite verbose flag. (0 to 10)*/
private Integer m_verbose = new Integer(1);
- private boolean m_parallel = false;
+ private String m_parallel = null;
/** JUnit compatibility flag. */
private Boolean m_isJUnit = Boolean.FALSE;
@@ -83,18 +87,16 @@ public void setFileName(String fileName) {
}
/**
- * Returns the parallel.
- * @return the parallel.
+ * Returns the parallel mode.
*/
- public boolean isParallel() {
+ public String getParallel() {
return m_parallel;
}
/**
- * Sets the parallel.
- * @param parallel The parallel to set.
+ * Sets the parallel mode
*/
- public void setParallel(boolean parallel) {
+ public void setParallel(String parallel) {
m_parallel = parallel;
}
@@ -317,7 +319,7 @@ public String toXml() {
Properties p = new Properties();
p.setProperty("name", getName());
p.setProperty("verbose", getVerbose().toString());
- p.setProperty("parallel", "" + isParallel());
+ p.setProperty("parallel", "" + getParallel());
p.setProperty("thread-count", "" + getThreadCount());
p.setProperty("annotations", getAnnotations());
@@ -394,7 +396,7 @@ public Object clone() {
result.setName(getName());
result.setAnnotations(getAnnotations());
- result.setParallel(isParallel());
+ result.setParallel(getParallel());
result.setThreadCount(getThreadCount());
result.setParameters(getAllParameters());
result.setVerbose(getVerbose());
View
22 src/main/org/testng/xml/XmlTest.java
@@ -28,7 +28,7 @@
private Map<String, List<String>> m_metaGroups = new HashMap<String, List<String>>();
private Map<String, String> m_parameters = new HashMap<String, String>();
- private Boolean m_isParallel = null;
+ private String m_parallel = null;
private String m_annotations = null;
// BeanShell expression
@@ -208,17 +208,17 @@ public String getParameter(String name) {
return result;
}
- public void setParallel(boolean parallel) {
- m_isParallel = new Boolean(parallel);
+ public void setParallel(String parallel) {
+ m_parallel = parallel;
}
- public boolean isParallel() {
- boolean result = false;
- if (null != m_isParallel) {
- result = m_isParallel.booleanValue();
+ public String getParallel() {
+ String result = null;
+ if (null != m_parallel) {
+ result = m_parallel;
}
else {
- result = m_suite.isParallel();
+ result = m_suite.getParallel();
}
return result;
@@ -253,8 +253,8 @@ public String toXml(String indent) {
Properties p = new Properties();
p.setProperty("name", getName());
p.setProperty("junit", m_isJUnit != null ? m_isJUnit.toString() : "false");
- if (null != m_isParallel) {
- p.setProperty("parallel", "" + m_isParallel);
+ if (null != m_parallel) {
+ p.setProperty("parallel", "" + m_parallel);
}
if (null != m_verbose) {
p.setProperty("verbose", m_verbose.toString());
@@ -423,7 +423,7 @@ public Object clone() {
result.setIncludedGroups(getIncludedGroups());
result.setExcludedGroups(getExcludedGroups());
result.setJUnit(isJUnit());
- result.setParallel(isParallel());
+ result.setParallel(getParallel());
result.setVerbose(getVerbose());
result.setParameters(getParameters());
result.setXmlPackages(getXmlPackages());
View
10 src/testng-1.0.dtd
@@ -28,10 +28,10 @@
<!-- name: The name of this suite (as it will appear in the reports) -->
<!-- verbose: (0-10) How verbose the output on the console -->
<!-- will be. This setting has no impact on the HTML reports -->
-<!-- parallel: (true|false) Whether TestNG should use different threads to -->
-<!-- run your tests (might speed up the process) -->
+<!-- parallel: (methods|tests) Whether TestNG should use different threads -->
+<!-- to run your tests (might speed up the process) -->
<!-- thread-count: An integer giving the size of the thread pool to use -->
-<!-- if you set parallel=true (default is 5) -->
+<!-- if you set parallel (default is 5) -->
<!-- annotations: (javadoc|JDK5) If "javadoc", TestNG will look for -->
<!-- JavaDoc annotations in your sources, otherwise it will -->
<!-- use JDK5 annotations -->
@@ -76,8 +76,8 @@
<!-- junit: (true|false) Whether to run in JUnit mode -->
<!-- verbose: (0-10) How verbose the output on the console -->
<!-- will be. This setting has no impact on the HTML reports -->
-<!-- parallel: (true|false) Whether TestNG should use different threads to -->
-<!-- run your tests (might speed up the process) -->
+<!-- parallel: (methods) Whether TestNG should use different threads -->
+<!-- to run your tests (might speed up the process) -->
<!-- annotations: (javadoc|JDK5) If "javadoc", TestNG will look for -->
<!-- JavaDoc annotations in your sources, otherwise it will -->
<!-- use JDK5 annotations -->
View
2  test-14/src/test/BaseTest.java
@@ -42,7 +42,7 @@ protected void setDebug() {
getTest().setVerbose(9);
}
- protected void setParallel(boolean parallel) {
+ protected void setParallel(String parallel) {
getTest().setParallel(parallel);
}
View
4 test-14/src/test/Test3.java
@@ -1,5 +1,7 @@
package test;
+import org.testng.xml.XmlSuite;
+
@@ -20,7 +22,7 @@ public Test3() {
*/
public void timeOut() {
addClass("test.sample.TimeOutTest");
- setParallel(true);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
"timeoutShouldPass",
View
3  test-14/src/test/thread/SequentialTest.java
@@ -1,6 +1,7 @@
package test.thread;
import org.testng.Assert;
+import org.testng.xml.XmlSuite;
import test.BaseTest;
@@ -11,7 +12,7 @@
*/
public void verifySequential() {
addClass("test.thread.SequentialSampleTest");
- setParallel(true);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
View
2  test-14/v4/src/test/BaseTest.java
@@ -42,7 +42,7 @@ protected void setDebug() {
getTest().setVerbose(9);
}
- protected void setParallel(boolean parallel) {
+ protected void setParallel(String parallel) {
getTest().setParallel(parallel);
}
View
4 test-14/v4/src/test/Test3.java
@@ -1,5 +1,7 @@
package test;
+import org.testng.xml.XmlSuite;
+
@@ -20,7 +22,7 @@ public Test3() {
*/
public void timeOut() {
addClass("test.sample.TimeOutTest");
- setParallel(true);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
"timeoutShouldPass",
View
2  test/src/test/BaseTest.java
@@ -44,7 +44,7 @@ protected void setDebug() {
getTest().setVerbose(9);
}
- protected void setParallel(boolean parallel) {
+ protected void setParallel(String parallel) {
getTest().setParallel(parallel);
}
View
3  test/src/test/Misc.java
@@ -1,6 +1,7 @@
package test;
import org.testng.annotations.*;
+import org.testng.xml.XmlSuite;
/**
* This class
@@ -13,7 +14,7 @@
public void makeSureSetUpWithParameterWithNoParametersFails() {
addClass("test.sample.SetUpWithParameterTest");
setVerbose(0);
- setParallel(false);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
};
View
5 test/src/test/Test3.java
@@ -1,6 +1,7 @@
package test;
import org.testng.annotations.Test;
+import org.testng.xml.XmlSuite;
/**
@@ -18,7 +19,7 @@ public Test3() {
@Test
public void timeOutInParallel() {
addClass("test.sample.TimeOutTest");
- setParallel(true);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
"timeoutShouldPass",
@@ -36,7 +37,7 @@ public void timeOutInParallel() {
@Test(enabled=false)
public void timeOutInNonParallel() {
addClass("test.sample.TimeOutTest");
- setParallel(false);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
"timeoutShouldPass",
View
1  test/src/test/thread/ParallelTestTest.java
@@ -31,6 +31,7 @@ public void verifySequential() {
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setName("ParallelTestTest");
+ xmlSuite.setParallel(XmlSuite.PARALLEL_TESTS);
List<XmlTest> tests = xmlSuite.getTests();
createTest(xmlSuite, class1);
createTest(xmlSuite, class2);
View
3  test/src/test/thread/SequentialTest.java
@@ -5,6 +5,7 @@
import org.testng.Assert;
import org.testng.annotations.Test;
+import org.testng.xml.XmlSuite;
import test.BaseTest;
@@ -35,7 +36,7 @@ public void verifySequential(int threadCount) {
addClass(class1);
addClass(class2);
addClass(class3);
- setParallel(true);
+ setParallel(XmlSuite.PARALLEL_METHODS);
setThreadCount(threadCount);
run();
View
2  test/v4/src/test/BaseTest.java
@@ -44,7 +44,7 @@ protected void setDebug() {
getTest().setVerbose(9);
}
- protected void setParallel(boolean parallel) {
+ protected void setParallel(String parallel) {
getTest().setParallel(parallel);
}
View
5 test/v4/src/test/Misc.java
@@ -1,6 +1,7 @@
package test;
-import org.testng.annotations.*;
+import org.testng.annotations.Test;
+import org.testng.xml.XmlSuite;
/**
* This class
@@ -13,7 +14,7 @@
public void makeSureSetUpWithParameterWithNoParametersFails() {
addClass("test.sample.SetUpWithParameterTest");
setVerbose(0);
- setParallel(false);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
};
View
5 test/v4/src/test/Test3.java
@@ -1,6 +1,7 @@
package test;
import org.testng.annotations.Test;
+import org.testng.xml.XmlSuite;
/**
@@ -18,7 +19,7 @@ public Test3() {
@Test
public void timeOutInParallel() {
addClass("test.sample.TimeOutTest");
- setParallel(true);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
"timeoutShouldPass",
@@ -34,7 +35,7 @@ public void timeOutInParallel() {
@Test(enabled=false)
public void timeOutInNonParallel() {
addClass("test.sample.TimeOutTest");
- setParallel(false);
+ setParallel(XmlSuite.PARALLEL_METHODS);
run();
String[] passed = {
"timeoutShouldPass",
Please sign in to comment.
Something went wrong with that request. Please try again.