Skip to content

Commit

Permalink
Merge pull request #8 from tcnh/ignoreSuiteSetupAndTearDown
Browse files Browse the repository at this point in the history
Ability to ignore suite setup and tear down
  • Loading branch information
fhoeben authored Apr 29, 2019
2 parents 9e3e24b + 072696f commit 218d394
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 49 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ To enable this listener in a project using the 'standard HSAC maven setup':
* set the maven property `extraFailsafeListeners` to `nl.hsac.fitnesse.junit.allure.JUnitAllureFrameworkListener`.

The listener creates data for Allure reporting in `target/allure-results`, to get an actual report you still need to
generate one based on these results.
generate one based on these results.

* If you wish to ignore SuiteSetUp and SuiteTearDown test pages in Allure, this can be achieved by setting system property skipSpecialPagesInAllure to true (`skipSpecialPagesInAllure=true`)

## Generating Allure Report

Expand Down
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<fitnesse.version>20161106</fitnesse.version>
<hsac.fixtures.version>2.12.4</hsac.fixtures.version>
<fitnesse.version>20190421</fitnesse.version>
<hsac.fixtures.version>4.4.0</hsac.fixtures.version>
<allure.version>1.5.4</allure.version>
</properties>

Expand All @@ -74,6 +74,7 @@
<artifactId>allure-java-adaptor-api</artifactId>
<version>${allure.version}</version>
</dependency>

</dependencies>

<build>
Expand All @@ -83,8 +84,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showDeprecation>true</showDeprecation>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package nl.hsac.fitnesse.junit.allure;

import fitnesse.junit.FitNessePageAnnotation;
import fitnesse.junit.FitNesseRunner;
import fitnesse.wiki.WikiPage;
import nl.hsac.fitnesse.fixture.Environment;
import nl.hsac.fitnesse.junit.HsacFitNesseRunner;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.junit.runner.Description;
Expand Down Expand Up @@ -42,15 +40,18 @@
/**
* JUnit listener for Allure Framework. Based on default ru.yandex.qatools.allure.junit.AllureRunListener
*/

public class JUnitAllureFrameworkListener extends RunListener {
private static final String SCREENSHOT_EXT = "png";
private static final String PAGESOURCE_EXT = "html";
private static final Pattern SCREENSHOT_PATTERN = Pattern.compile("href=\"([^\"]*." + SCREENSHOT_EXT + ")\"");
private static final Pattern PAGESOURCE_PATTERN = Pattern.compile("href=\"([^\"]*." + PAGESOURCE_EXT + ")\"");
private static final Pattern SPECIAL_PAGE_PATTERN = Pattern.compile(".*(\\.SuiteSetUp|\\.SuiteTearDown)$");
private final Environment hsacEnvironment = Environment.getInstance();
private final HashMap<String, String> suites;
protected final Label hostLabel;
private final Label hostLabel;
private final Allure allure;
private boolean skipSpecialPages;

public JUnitAllureFrameworkListener() {
this.allure = Allure.LIFECYCLE;
Expand All @@ -64,71 +65,80 @@ public JUnitAllureFrameworkListener() {
hostLabel = new Label();
hostLabel.setName("host");
hostLabel.setValue(hostName);
skipSpecialPages = null != System.getProperty("skipSpecialPagesInAllure") ?
Boolean.valueOf(System.getProperty("skipSpecialPagesInAllure")) : false;
}

private void testSuiteStarted(Description description) {
String uid = this.generateSuiteUid(description.getDisplayName());
String suiteName = System.getProperty(HsacFitNesseRunner.SUITE_OVERRIDE_VARIABLE_NAME);
if (null == suiteName) {
suiteName = description.getAnnotation(FitNesseRunner.Suite.class).value();
}
String uid = this.generateSuiteUid(description.getDisplayName());
String suiteName = description.getClassName();

TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, suiteName);
AnnotationManager am = new AnnotationManager(description.getAnnotations());
am.update(event);
event.withLabels(AllureModelUtils.createTestFrameworkLabel("FitNesse"));
getAllure().fire(event);
}


public void testStarted(Description description) {
FitNessePageAnnotation pageAnn = description.getAnnotation(FitNessePageAnnotation.class);
if (pageAnn != null) {
TestCaseStartedEvent event = new TestCaseStartedEvent(this.getSuiteUid(description), description.getMethodName());
TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, suiteName);
AnnotationManager am = new AnnotationManager(description.getAnnotations());
am.update(event);

this.fireClearStepStorage();
event.withLabels(AllureModelUtils.createTestFrameworkLabel("FitNesse"));
getAllure().fire(event);
}

WikiPage page = pageAnn.getWikiPage();
addLabels(page);
@Override
public void testStarted(Description description) {
if (reportTestPage(description.getMethodName())) {
FitNessePageAnnotation pageAnn = description.getAnnotation(FitNessePageAnnotation.class);
if (pageAnn != null) {
TestCaseStartedEvent event = new TestCaseStartedEvent(this.getSuiteUid(description), description.getMethodName());
AnnotationManager am = new AnnotationManager(description.getAnnotations());
am.update(event);

this.fireClearStepStorage();
getAllure().fire(event);

WikiPage page = pageAnn.getWikiPage();
addLabels(page);
}
}
}

@Override
public void testFailure(Failure failure) {
Description description = failure.getDescription();
if (description.isTest()) {
Throwable exception = failure.getException();
List<Pattern> patterns = new ArrayList<>();
patterns.add(SCREENSHOT_PATTERN);
patterns.add(PAGESOURCE_PATTERN);
processAttachments(exception, patterns);

this.fireTestCaseFailure(exception);
this.recordTestResult(description);

} else {
this.startFakeTestCase(description);
this.fireTestCaseFailure(failure.getException());
this.finishFakeTestCase();
if (reportTestPage(description.getMethodName())) {
if (description.isTest()) {
Throwable exception = failure.getException();
List<Pattern> patterns = new ArrayList<>();
patterns.add(SCREENSHOT_PATTERN);
patterns.add(PAGESOURCE_PATTERN);
processAttachments(exception, patterns);

this.fireTestCaseFailure(exception);
this.recordTestResult(description);

} else {
this.startFakeTestCase(description);
this.fireTestCaseFailure(failure.getException());
this.finishFakeTestCase();
}
}
}

@Override
public void testAssumptionFailure(Failure failure) {
this.testFailure(failure);
}

@Override
public void testFinished(Description description) {
String methodName = description.getMethodName();
makeAttachment(fitnesseResult(methodName).getBytes(), "FitNesse Result page", "text/html");
getAllure().fire(new TestCaseFinishedEvent());
if (reportTestPage(description.getMethodName())) {
String methodName = description.getMethodName();
makeAttachment(fitnesseResult(methodName).getBytes(), "FitNesse Result page", "text/html");
getAllure().fire(new TestCaseFinishedEvent());
}
}

private void testSuiteFinished(String uid) {
getAllure().fire(new TestSuiteFinishedEvent(uid));
}

@Override
public void testRunFinished(Result result) throws IOException {

for (String uid : this.getSuites().values()) {
Expand Down Expand Up @@ -182,7 +192,7 @@ private Allure getAllure() {
return this.allure;
}

public Map<String, String> getSuites() {
private Map<String, String> getSuites() {
return this.suites;
}

Expand Down Expand Up @@ -250,7 +260,7 @@ private void addLabels(WikiPage page) {
getAllure().fire(event);
}

protected List<Label> createLabels(WikiPage page) {
private List<Label> createLabels(WikiPage page) {
List<Label> labels = new ArrayList<>();

String suiteName = page.getParent().getName();
Expand All @@ -272,12 +282,16 @@ protected List<Label> createLabels(WikiPage page) {
return labels;
}

protected String[] getTags(WikiPage page) {
private String[] getTags(WikiPage page) {
String[] tags = new String[0];
String tagInfo = page.getData().getProperties().get("Suites");
if (null != tagInfo) {
tags = tagInfo.split(",");
}
return tags;
}

private boolean reportTestPage(String pageName) {
return !skipSpecialPages || !SPECIAL_PAGE_PATTERN.matcher(pageName).matches();
}
}

0 comments on commit 218d394

Please sign in to comment.