forked from serenity-bdd/serenity-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for flagging new tests
Set show.history.flag=true to allow new failures to be flagged in the reports.
- Loading branch information
Showing
14 changed files
with
379 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pipeline { | ||
agent any | ||
|
||
tools { | ||
maven 'Gradle 3.4' | ||
jdk 'jdk8' | ||
} | ||
|
||
stages { | ||
stage('Test') { | ||
steps { | ||
sh './gradlew clean test' | ||
sh './gradlew integrationTests' | ||
sh './gradlew browserTests' | ||
} | ||
post { | ||
always { | ||
junit 'target/surefire-reports/**/*.xml, **/build/reports/integration-tests/TEST-*.xml' | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
serenity-core/src/main/java/net/serenitybdd/core/history/ClearDirectoryContents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.serenitybdd.core.history; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
class ClearDirectoryContents implements PrepareHistoryDirectory { | ||
|
||
@Override | ||
public void prepareHistoryDirectory(Path historyDirectory) throws IOException { | ||
FileUtils.cleanDirectory(historyDirectory.toFile()); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...core/src/main/java/net/serenitybdd/core/history/FileSystemTestOutcomeSummaryRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package net.serenitybdd.core.history; | ||
|
||
import com.google.common.base.Optional; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.inject.Inject; | ||
import net.thucydides.core.guice.Injectors; | ||
import net.thucydides.core.model.ReportNamer; | ||
import net.thucydides.core.model.ReportType; | ||
import net.thucydides.core.model.TestOutcome; | ||
import net.thucydides.core.reports.AcceptanceTestLoader; | ||
import net.thucydides.core.reports.json.JSONTestOutcomeReporter; | ||
import net.thucydides.core.reports.json.gson.GsonPreviousOutcomeConverter; | ||
import net.thucydides.core.util.EnvironmentVariables; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.*; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static net.thucydides.core.ThucydidesSystemProperty.SERENITY_HISTORY_DIRECTORY; | ||
|
||
public class FileSystemTestOutcomeSummaryRecorder implements TestOutcomeSummaryRecorder { | ||
|
||
private final Path historyDirectory; | ||
private final Boolean deletePreviousHistory; | ||
private final AcceptanceTestLoader testOutcomeReporter = new JSONTestOutcomeReporter(); | ||
private final GsonPreviousOutcomeConverter previousOutcomeConverter; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(FileSystemTestOutcomeSummaryRecorder.class); | ||
|
||
private static Map<Boolean, PrepareHistoryDirectory> DELETE_STRATEGY = | ||
ImmutableMap.of( | ||
false, new LeaveDirectoryContents(), | ||
true, new ClearDirectoryContents() | ||
); | ||
|
||
|
||
@Inject | ||
public FileSystemTestOutcomeSummaryRecorder(EnvironmentVariables environmentVariables) { | ||
this(Paths.get(SERENITY_HISTORY_DIRECTORY.from(environmentVariables, "history"),""), false); | ||
} | ||
|
||
/** | ||
* Used mainly from Maven | ||
*/ | ||
public FileSystemTestOutcomeSummaryRecorder(Path historyDirectory, Boolean deletePreviousHistory) { | ||
this.historyDirectory = historyDirectory; | ||
this.deletePreviousHistory = deletePreviousHistory; | ||
previousOutcomeConverter = new GsonPreviousOutcomeConverter(Injectors.getInjector().getInstance(EnvironmentVariables.class)); | ||
} | ||
|
||
@Override | ||
public void recordOutcomeSummariesFrom(Path sourceDirectory) { | ||
|
||
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(sourceDirectory)) { | ||
|
||
usingDeleteStrategyFor(deletePreviousHistory).prepareHistoryDirectory(historyDirectory); | ||
|
||
for (Path path : directoryStream) { | ||
storeOutcomesFrom(testOutcomeReporter.loadReportFrom(path).asSet()); | ||
} | ||
} catch (IOException ex) { | ||
LOGGER.warn("Unable to store test outcome for posterity", ex); | ||
} | ||
} | ||
|
||
private void storeOutcomesFrom(Set<TestOutcome> testOutcomes) throws IOException { | ||
for (TestOutcome testOutcome : testOutcomes) { | ||
PreviousTestOutcome summary = PreviousTestOutcome.from(testOutcome); | ||
File summaryFile = summaryFileFor(testOutcome); | ||
|
||
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(summaryFile))) { | ||
previousOutcomeConverter.toJson(summary, outputStream); | ||
outputStream.flush(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public List<PreviousTestOutcome> loadSummaries() { | ||
List<PreviousTestOutcome> previousTestOutcomes = new ArrayList<>(); | ||
|
||
if (historyDirectory.toFile().exists()) { | ||
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(historyDirectory)) { | ||
for (Path path : directoryStream) { | ||
previousTestOutcomes.addAll(previousTestOutcomesFrom(path).asSet()); | ||
} | ||
} catch (IOException ex) { | ||
LOGGER.warn("Unable to store test outcome for posterity", ex); | ||
} | ||
} | ||
|
||
return previousTestOutcomes; | ||
} | ||
|
||
private Optional<PreviousTestOutcome> previousTestOutcomesFrom(Path source) { | ||
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(source.toFile()))) { | ||
return previousOutcomeConverter.fromJson(inputStream); | ||
} catch (IOException e) { | ||
return Optional.absent(); | ||
} | ||
} | ||
|
||
private PrepareHistoryDirectory usingDeleteStrategyFor(Boolean deletePreviousHistory) { | ||
return DELETE_STRATEGY.get(deletePreviousHistory); | ||
} | ||
|
||
private File summaryFileFor(TestOutcome testOutcome) { | ||
String summaryFilename = ReportNamer.forReportType(ReportType.JSON).withPrefix("summary-").getNormalizedTestNameFor(testOutcome); | ||
return historyDirectory.resolve(summaryFilename).toFile(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
serenity-core/src/main/java/net/serenitybdd/core/history/LeaveDirectoryContents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.serenitybdd.core.history; | ||
|
||
import java.nio.file.Path; | ||
|
||
class LeaveDirectoryContents implements PrepareHistoryDirectory { | ||
|
||
@Override | ||
public void prepareHistoryDirectory(Path historyDirectory) {} | ||
} |
8 changes: 8 additions & 0 deletions
8
serenity-core/src/main/java/net/serenitybdd/core/history/PrepareHistoryDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.serenitybdd.core.history; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
interface PrepareHistoryDirectory { | ||
void prepareHistoryDirectory(Path historyDirectory) throws IOException; | ||
} |
Oops, something went wrong.