public static void run( Class[] testClasses, String testSourceDirectory, Map options, RunListener reportManager,
TestNgTestSuite suite, File reportsDirectory, final String methodNamePattern )
throws TestSetFailedException
{
TestNG testng = new TestNG( true );
Configurator configurator = getConfigurator( (String) options.get( "testng.configurator" ) );
System.out.println( "Configuring TestNG with: " + configurator.getClass().getSimpleName() );
XmlMethodSelector groupMatchingSelector = getGroupMatchingSelector( options );
XmlMethodSelector methodNameFilteringSelector = getMethodNameFilteringSelector( methodNamePattern );
Map<String, SuiteAndNamedTests> suitesNames = new HashMap<String, SuiteAndNamedTests>();
List<XmlSuite> xmlSuites = new ArrayList<XmlSuite>();
for ( Class testClass : testClasses )
{
TestMetadata metadata = findTestMetadata( testClass );
SuiteAndNamedTests suiteAndNamedTests = suitesNames.get( metadata.suiteName );
if ( suiteAndNamedTests == null )
{
suiteAndNamedTests = new SuiteAndNamedTests();
suiteAndNamedTests.xmlSuite.setName( metadata.suiteName );
configurator.configure( suiteAndNamedTests.xmlSuite, options );
xmlSuites.add( suiteAndNamedTests.xmlSuite );
suitesNames.put( metadata.suiteName, suiteAndNamedTests );
}
XmlTest xmlTest = suiteAndNamedTests.testNameToTest.get( metadata.testName );
if ( xmlTest == null )
{
xmlTest = new XmlTest( suiteAndNamedTests.xmlSuite );
xmlTest.setName( metadata.testName );
addSelector( xmlTest, groupMatchingSelector );
addSelector( xmlTest, methodNameFilteringSelector );
xmlTest.setXmlClasses( new ArrayList<XmlClass>() );
suiteAndNamedTests.testNameToTest.put( metadata.testName, xmlTest );
}
xmlTest.getXmlClasses().add( new XmlClass( testClass.getName() ) );
}
testng.setXmlSuites( xmlSuites );
configurator.configure( testng, options );
postConfigure( testng, testSourceDirectory, reportManager, suite, reportsDirectory );
testng.run();
}