Implemented -methods
diff --git a/build.xml b/build.xml
index 11f6ffb..bb17ec7 100644
--- a/build.xml
+++ b/build.xml
@@ -191,11 +191,12 @@
<target name="dist-all-zip" depends="dist-prepare,javadocs">
<property name="zip.dir" value="testng-${testng.version}" />
+ <echo>Adding ${testng.fullname}</echo>
<zip zipfile="${testng.zip}">
- <zipfileset prefix="${zip.dir}" dir="${basedir}" includesfile="FILES" />
- <zipfileset prefix="${zip.dir}" dir="${basedir}">
- <include name="${testng.jar}" />
+ <zipfileset prefix="${zip.dir}" dir="${target}">
+ <include name="${testng.fullname}.jar" />
</zipfileset>
+ <zipfileset prefix="${zip.dir}" dir="${basedir}" includesfile="FILES" />
<zipfileset dir="${other.jars.dir}" prefix="${zip.dir}/${other.jars.dir}"/>
<zipfileset dir="javadocs" prefix="${zip.dir}/javadocs" />
<zipfileset dir="src" prefix="${zip.dir}/src" />
diff --git a/src/main/java/org/testng/CommandLineArgs.java b/src/main/java/org/testng/CommandLineArgs.java
index 290e26c..f681402 100644
--- a/src/main/java/org/testng/CommandLineArgs.java
+++ b/src/main/java/org/testng/CommandLineArgs.java
@@ -1,9 +1,11 @@
package org.testng;
import com.beust.jcommander.Parameter;
+import com.beust.jcommander.converters.CommaSeparatedConverter;
import org.testng.collections.Lists;
+import java.util.ArrayList;
import java.util.List;
public class CommandLineArgs {
@@ -94,10 +96,13 @@
@Parameter(names = "-host", description = "The host")
public String host;
- @Parameter(names = "-master", description ="Host where the master is")
+ @Parameter(names = "-master", description = "Host where the master is")
public String master;
- @Parameter(names = "-slave", description ="Host where the slave is")
+ @Parameter(names = "-slave", description = "Host where the slave is")
public String slave;
+ @Parameter(names = "-methods", description = "Comma separated of test methods",
+ converter = CommaSeparatedConverter.class)
+ public List<String> commandLineMethods = new ArrayList<String>();
}
diff --git a/src/main/java/org/testng/TestNG.java b/src/main/java/org/testng/TestNG.java
index c95778b..a1e8c71 100644
--- a/src/main/java/org/testng/TestNG.java
+++ b/src/main/java/org/testng/TestNG.java
@@ -33,6 +33,7 @@
import org.testng.reporters.XMLReporter;
import org.testng.xml.Parser;
import org.testng.xml.XmlClass;
+import org.testng.xml.XmlInclude;
import org.testng.xml.XmlMethodSelector;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
@@ -117,6 +118,7 @@
private static JCommander m_jCommander;
+ private List<String> m_commandLineMethods;
protected List<XmlSuite> m_suites = Lists.newArrayList();
protected List<XmlSuite> m_cmdlineSuites;
protected String m_outputDir = DEFAULT_OUTPUTDIR;
@@ -493,7 +495,6 @@
m_cmdlineSuites.add(suite);
m_suites.add(suite);
}
-
/**
* Set the test classes to be run by this TestNG object. This method
@@ -508,8 +509,46 @@
m_suites.clear();
m_commandLineTestClasses = classes;
}
-
- private List<XmlSuite> createCommandLineSuites(Class[] classes) {
+
+ private String[] splitMethod(String m) {
+ int index = m.lastIndexOf(".");
+ if (index < 0) {
+ throw new TestNGException("Bad format for command line method:" + m);
+ }
+
+ return new String[] { m.substring(0, index), m.substring(index + 1) };
+ }
+
+ private List<XmlSuite> createCommandLineSuitesForMethods(List<String> commandLineMethods) {
+ //
+ // Create the <classes> tag
+ //
+ Set<Class> classes = Sets.newHashSet();
+ for (String m : commandLineMethods) {
+ classes.add(ClassHelper.forName(splitMethod(m)[0]));
+ }
+
+ List<XmlSuite> result = createCommandLineSuitesForClasses(classes.toArray(new Class[0]));
+
+ //
+ // Add the method tags
+ //
+ List<XmlClass> xmlClasses = result.get(0).getTests().get(0).getXmlClasses();
+ for (XmlClass xc : xmlClasses) {
+ for (String m : commandLineMethods) {
+ String[] split = splitMethod(m);
+ String className = split[0];
+ if (xc.getName().equals(className)) {
+ XmlInclude includedMethod = new XmlInclude(split[1]);
+ xc.getIncludedMethods().add(includedMethod);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private List<XmlSuite> createCommandLineSuitesForClasses(Class[] classes) {
//
// See if any of the classes has an xmlSuite or xmlTest attribute.
// If it does, create the appropriate XmlSuite, otherwise, create
@@ -725,6 +764,7 @@
/** The list of test names to run from the given suite */
private List<String> m_testNames;
+
/**
* Sets the level of verbosity. This value will override the value specified
* in the test suites.
@@ -738,15 +778,21 @@
}
private void initializeCommandLineSuites() {
- if(null != m_commandLineTestClasses) {
+ if (m_commandLineTestClasses != null || m_commandLineMethods != null) {
initializeInjector();
- m_cmdlineSuites = createCommandLineSuites(m_commandLineTestClasses);
+ if (null != m_commandLineMethods) {
+ m_cmdlineSuites = createCommandLineSuitesForMethods(m_commandLineMethods);
+ }
+ else {
+ m_cmdlineSuites = createCommandLineSuitesForClasses(m_commandLineTestClasses);
+ }
+
for (XmlSuite s : m_cmdlineSuites) {
m_suites.add(s);
}
}
}
-
+
private void initializeCommandLineSuitesParams() {
if(null == m_cmdlineSuites) {
return;
@@ -1228,6 +1274,10 @@
addReporter(reporterConfig);
}
+ if (cla.commandLineMethods.size() > 0) {
+ m_commandLineMethods = cla.commandLineMethods;
+ }
+
if (cla.suiteFiles != null) setTestSuites(cla.suiteFiles);
}
diff --git a/src/test/java/test/CommandLineTest.java b/src/test/java/test/CommandLineTest.java
index e230bde..ee26b43 100644
--- a/src/test/java/test/CommandLineTest.java
+++ b/src/test/java/test/CommandLineTest.java
@@ -108,6 +108,25 @@
}, null);
}
+ @Test
+ public void testMethodParameter() {
+ String[] argv = {
+ "-log", "0",
+ "-d", OutputDirectoryPatch.getOutputDirectory(),
+ "-methods", "test.sample.Sample2.method1,test.sample.Sample2.method3",
+ };
+ TestListenerAdapter tla = new TestListenerAdapter();
+ TestNG.privateMain(argv, tla);
+
+ List<ITestResult> passed = tla.getPassedTests();
+ Assert.assertEquals(passed.size(), 2);
+ Assert.assertTrue((passed.get(0).getName().equals("method1") &&
+ passed.get(1).getName().equals("method3"))
+ ||
+ (passed.get(1).getName().equals("method1") &&
+ passed.get(0).getName().equals("method3")));
+ }
+
private static void ppp(String s) {
System.out.println("[CommandLineTest] " + s);
}
diff --git a/upload-beta b/upload-beta
index 6ab60dc..659dc16 100755
--- a/upload-beta
+++ b/upload-beta
@@ -1,4 +1,4 @@
#scp `ls -tr *beta.zip|tail -1` cedric@beust.com:w/testng
-scp `ls -tr target/*beta.zip|tail -1` beust.com@s98219.gridserver.com:w/testng
+scp `ls -tr target/*beta.zip|tail -1` beust.com@s98219.gridserver.com:domains/testng.org/html