Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reverted from v. 17

...

Code Block
git clone git://github.com/xored/q7.extensions.reporting.git 
cd q7.extensions
mvn clean install -f reporting/pom.xml
cd runner 
mvn clean install 

Build will provide a update site for sample plugin, it could be installed directly into Q7 RCP.
And a customized q7runner version with sample plugin included.

...

Code Block
package com.xored.q7.reporting.core;
import java.io.OutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
/**
 * Entry point for report generation from Q7.
 * 
 * Receive file factory and list of per test reports to generate for.
 * 
 * Same report renderer are used for report generation in Q7 RCP and in Q7
 * runner.
 * 
 * Report renderer receive Q7ReportIterator to iterate over all reports in
 * execution.
 * 
 */
public interface IReportRenderer {
 /**
 * Renderer should implement interface to recieve progress monitor then
 * report renderer are executed from Q7 report wizard.
 */
 interface ProgressMonitorSupport {
      void setProgressMonitor(IProgressMonitor monitor);
 }
 public interface IContentFactory {
 /**
 * Create new file output stream in user specified location. User
 * specify location in Q7 RCP report wizard, or in Q7 runner.
 * 
 * @param fname
 * - file name to create.
 * @return - Buffered file output stream.
 */
 OutputStream createFileStream(String fname);
 /**
 * Creates new folder in user specified location.User specify location
 * in Q7 RCP report wizard, or in Q7 runner.
 * 
 * @param name
 * - folder name
 * @return - new content factory based on created folder.
 */
 IContentFactory createFolder(String name);
 /**
 * Check for file are existing in location or not.
 * 
 * @param fname
 * - file name.
 * @return - true if file are exists, false otherwise.
 */
 boolean isFileExist(String fname);
 }
 /**
 * Receive a file factory to generate report in. And a list of test
 * execution reports by Q7ReportIterrator..
 * 
 * @param factory
 * - file factory
 * @param reportName
 * - report name to generate. User specified in UI.
 * @param report
 * - report iterator.
 * @return - Eclipse platform status object. Display error in UI if failed
 * to render report.
 */
 IStatus generateReport(IContentFactory factory, String reportName,
 Q7ReportIterator report);
 /**
 * Return a list of files will be generated by report, to show user
 * confirmations in UI.
 * 
 * @param reportName
 * - user specified report name.
 * @return - Array of file names. Names then will be checked using
 * isFileExist() for otherwrite confirmation to display.
 */
 String[] getGeneratedFileNames(String reportName);
} 

...

Code Block
public class Sample1StatisticsReportRenderer implements IReportRenderer {
 public Sample1StatisticsReportRenderer() {
 }
 
 public IStatus generateReport(IContentFactory factory, String reportName, Q7ReportIterator report) {
 OutputStream outputStream = null;
 try {
     outputStream = factory.createFileStream(reportName + ".sample.report.txt");
     BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
     writer.append("Simple report sample:\n");
     writer.append("tests:\n");
     report.reset();
     while (report.hasNext()) {
         Report oneReport = report.next();
         if (oneReport == null) {
             break;
         }

         Node localRoot = oneReport.getRoot();
         // Skip nodes without specific Q7 info node stored in
         if (!localRoot.getProperties().containsKey(IQ7ReportConstants.ROOT)) {
             continue;
         }
         Q7Info q7info = (Q7Info) localRoot.getProperties().get(
         IQ7ReportConstants.ROOT);
         String resultLine = "";
         switch (q7info.getResult()) {
             case FAIL:
             case WARN:
                  resultLine += "Failed";
                  break;
             case PASS:
                  resultLine += "Passed";
                  break;
             case SKIPPED:
                  resultLine += "Skipped";
                  break;
         }
         resultLine += " testcase: " + localRoot.getName();
         resultLine += " execution time: " + (localRoot.getEndTime() - localRoot.getStartTime());
         writer.append(resultLine + "\n");
     }
     writer.close();
 } catch (IOException e) {
     e.printStackTrace();
 } finally {
    if (outputStream != null) {
         try {
             outputStream.close();
         } catch (Throwable e) {
    }
 }
 }
 return Status.OK_STATUS;
 }

 public String[] getGeneratedFileNames(String reportName) {
     return new String[] { reportName + ".sample.report.txt" };
 }
}

Some details about report format and used structured will be described below.

...

Code Block
public class Q7ReportIterator extends ... {
 /**
 * Construct report iterator based on existing file object.
 * 
 * To load reports from some custom input, please use
 * <code>SherlockReportFormat</code>
 * 
 * @param file
 * - q7.report file.
 */
 public SherlockReportIterator(File file);
 /**
 * Reset current iterator and start from begining.
 */
 public void reset();
 /**
 * Check for next report are exists.
 * 
 * @return true if report exists, false otherwise.
 */
 public boolean hasNext();
 /**
 * Read and load next execution report.
 * 
 * @return Report object if report build be loaded.
 */
 public Report next();
 /**
 * Close previously opened iteration.
 */
 public void close();
 /**
 * Return report file specified in constructor.
 * 
 * @return report file.
 */
 public File getReportFile();
};

Following example could illustrate how to iterate over Q7 report file:

...

  1. Clone our example repository.

    Code Block
    git clone git://github.com/xored/q7.extensions.reporting.git 
  2. Customize q7.extensions/runner/pom.xml.
    1. Update groupId to be one you like. Default value is "com.xored.q7_my". 
    2. Specify update site with extension plugins to use.
  3. Customize q7.extensions/runner/q7runner.product to contain required for extension features. Committed version contain link to example repository.

  4. Build q7 runner

    Code Block
    cd runner
    mvn clean install 

    Build will provide archived version of q7runner in target folder and will install q7runner into local maven repository.

  5. Execute q7runner or maven plugin.
    Please refer to Q7 Runner for more information about runner.
    And Q7 Maven Pluginfor more information about using maven plugin.
    1. Using command line.
      Please also specify parameter "-report  sample1;/path/reportfolder/reportName".
      This will tell Q7 runner to use report renderer with id "sample1" and to put report file with reportName into folder /path/reportfolder
    2. Using maven plugin.
      Please change q7-maven-plugin version to 1.2.1-SNAPSHOT.
      And when in configuration area of q7-maven-plugin please do following modifications.

      Code Block
      <report>
          <id>sample1</id>
          <name>myreport</name>
      </report>
      <q7>
          <version>1.2.0-SNAPSHOT</version>
          <groupId>com.xored.q7_my</groupId> <!-- Or any group id if modified in step 2 -->   
      </q7>