/** * Removes test cases from the test suite. The test cases to be removed are derived from the * includes and excludes collections contained in the test suite info object. * * @param suite - The test suite * @param testCases - The list of test cases to consider */ private static void removeTestCases(TestSuiteInfo suite, List<ITestCaseDescriptor> testCases) { final Collection<String> includes = suite.getTestCaseIncludes(); final Collection<String> excludes = suite.getTestCaseExcludes(); final int includesSize = includes.size(); final int excludesSize = excludes.size(); assert Conditionals.implies(includesSize > 0, excludesSize == 0); assert Conditionals.implies(excludesSize > 0, includesSize == 0); /* * Handle the include test cases by removing test cases by removing test * case that are NOT in the includes set. */ if (includesSize > 0) { final Comparator comp = new Comparator() { public int compare( final String currentTestCaseId, final Collection<String> testCaseIds) { int comparison = 0; for (String testCaseId : testCaseIds) { comparison += currentTestCaseId.equals(testCaseId) ? 1 : 0; } return comparison; } }; removeTestCaseDescriptors(testCases, includes, comp); } /* * Handle the excludes test cases by removing the test cases specified in * the exclude set. */ if (excludesSize > 0) { final Comparator comp = new Comparator() { public int compare( final String currentTestCaseId, final Collection<String> testCaseIds) { for (String testCaseId : testCaseIds) { if (currentTestCaseId.equals(testCaseId)) { return 0; } } return 1; } }; removeTestCaseDescriptors(testCases, excludes, comp); } }
/** * Set up and run a test suite * * @param suite * @param testInputProv * @param resultMgr * @param reporter * @throws Exception */ private static boolean setUpAndRunTestSuite( TestSuiteInfo suite, ITRTestInputProvider testInputProv, ITRTestOutputManager resultMgr, IReportFacade reporter) { final String component = suite.getComponent(); List<ITestCaseDescriptor> testCases = null; // Setup the test suite // TODO: Move the suite setup to org.splandroid.tr.testing pkg? reporter.startingTestSuiteSetUp(component); try { testCases = setUpTestSuite(suite, testInputProv, resultMgr); removeTestCases(suite, testCases); } catch (Exception ex) { logger.fatal( String.format( "Processing of test suite set-up for component [%s] failed: %s", component, ex.getMessage()), ex); reporter.errorTestSuiteSetUp(component, ex); return false; } reporter.finishedTestSuiteSetUp(component); // Run the test suite final boolean passed = runTestSuite(component, testCases, testInputProv, resultMgr, reporter); logger.info(String.format("Finished test suite for [%s]", component)); return passed; }
/** * Setup the configuration for a test suite. This method reads the profile.xml for the component * to define the tags/attributes in the component's tests.xml file. The tests.xml file then drives * the running of the tests. * * @param component - Name of the component in RCS * @throws TRException */ private static List<ITestCaseDescriptor> setUpTestSuite( TestSuiteInfo suite, ITRTestInputProvider testInputProv, ITRTestOutputManager resultMgr) throws Exception { final String component = suite.getComponent(); final InputStream profileStream = testInputProv.getProfileFileStream(); logger.debug(String.format("Parsing profile for [%s]...", component)); final ISymbolMap symbols = new SymbolMap(); final IParser profileParser = new ProfileParser(); profileParser.setSymbolTable(symbols).parse(profileStream); logger.debug(String.format("Parsing tests for [%s]...", component)); final InputStream testsFile = testInputProv.getTestsFileStream(); final List<ITestCaseDescriptor> testCases = new ArrayList<ITestCaseDescriptor>(); final IParser testsParser = new TestsParser(testCases); testsParser.setSymbolTable(symbols).parse(testsFile); return testCases; }
public static void main(String[] args) { // Create the command line processor final CommandLineProcessor cliProcessor = new CommandLineProcessor( applicationName.toUpperCase() + usageMessage, defaultTestInfoDirName, defaultTestResultsDirName, defaultPropertiesFileName, defaultLogFileName); // Process command line try { final boolean shouldExit = cliProcessor.process(args); if (shouldExit == true) { System.exit(0); } } catch (TRException ex) { ex.printStackTrace(); System.exit(1); } // Time of test final Date timeNow = new Date(); // Build test input and result providers/managers. final String testInfoDir = cliProcessor.getTestInfoDirectory(); final ITRTestInputProvider testInputProv = new TRTestInputProvider(testInfoDir); final String testResultsDir = cliProcessor.getTestResultsDirectory(); final ITRTestOutputManager resultMgr = new TRTestOutputManager(testResultsDir, timeNow); final File suiteResultDir = resultMgr.createSuiteResultsDirectory(); // Load properties final String propsFile = cliProcessor.getPropertiesFile(); final String logFile = new File(suiteResultDir, cliProcessor.getLogFile()).getAbsolutePath(); try { final Properties properties = loadProperties(propsFile, logFile); PropertyConfigurator.configure(properties); } catch (Exception ex) { System.out.printf("Failed to load properties: %s\n", ex.getMessage()); System.exit(1); } // Sort out log level Level logLevel = null; switch (cliProcessor.getLogLevel()) { case DEBUG: logLevel = Level.DEBUG; break; case INFO: logLevel = Level.INFO; break; case WARN: logLevel = Level.WARN; break; case ERROR: logLevel = Level.ERROR; break; case FATAL: logLevel = Level.FATAL; break; default: assert false : "Bad log level"; } Logger.getRootLogger().setLevel(logLevel); logger = Logger.getLogger(Main.class); // Create reporters final IEventObserver logFileReporter = new org.splandroid.tr.reporters.logfile.Reporter(); // final IReporter htmlFileReporter = // new org.splandroid.tr.reporting.html.Reporter(resultMgr); final IReportFacade reporter = TRTestReportFactory.getReporter(logFileReporter); reporter.started("Test harness"); // For each test suite do... final Collection<TestSuiteInfo> suites = cliProcessor.getTestSuites(); for (TestSuiteInfo suite : suites) { // Notify objects of the current component under test final String componentUnderTest = suite.getComponent(); testInputProv.setComponent(componentUnderTest); resultMgr.setComponent(componentUnderTest); reporter.setComponent(componentUnderTest); reporter.startingComponent(); final boolean passed = setUpAndRunTestSuite(suite, testInputProv, resultMgr, reporter); if (passed == true) { reporter.passedComponent(); } else { reporter.failedComponent(); } } reporter.finished("Test harness"); }