/** * 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"); }