com.pdsl.reports.DefaultTestResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pdsl Show documentation
Show all versions of pdsl Show documentation
The Polymorphic DSL test framework was designed to solve the challenges with testing large, complex systems. Modern architecture requires software to run as distrubited systems or on multiple platforms. The conventional cost of testing these systems is quite high.
PDSL allows a user to describe the system under test using a DSL of some kind: a picture,
sentences in natural languages, graphs, etc. Using a common DSL allows someone to make deeply scalable tests. A simple change to the DSL could generate dozens of tests providing coverage through many layers of the test pyramid or even multiple applications.
package com.pdsl.reports;
import com.google.common.base.Preconditions;
import com.pdsl.reports.proto.TechnicalReportData;
import com.pdsl.specifications.Phrase;
import com.pdsl.testcases.TestCase;
import java.util.Optional;
public class DefaultTestResult implements TestResult {
private final TechnicalReportData.Status status;
private final TestCase testCase;
private int phrasesSkippedDueToFailure = 0;
private int passingPhraseTotal = 0;
private Optional failingPhrase = Optional.empty();
private Optional failureReason = Optional.empty();
public DefaultTestResult(int passingPhraseTotal, TestCase testCase, TechnicalReportData.Status status) {
this.status = status;
this.passingPhraseTotal = passingPhraseTotal;
this.testCase = testCase;
}
public DefaultTestResult(int passingPhraseTotal, int phrasesSkippedDueToFailure, Phrase failingStep, Throwable failureReason, TestCase testCase) {
Preconditions.checkArgument(passingPhraseTotal >= 0, "Passing phrases cannot be negative");
Preconditions.checkArgument(phrasesSkippedDueToFailure >= 0, "Failing phrases cannot be negative");
this.status = TechnicalReportData.Status.FAILED;
this.passingPhraseTotal = passingPhraseTotal;
this.phrasesSkippedDueToFailure = phrasesSkippedDueToFailure;
this.failingPhrase = Optional.of(failingStep);
this.failureReason = Optional.of(failureReason);
this.testCase = testCase;
}
public static DefaultTestResult failedTest(TestCase testCase, Phrase failingPhrase, Throwable failureReason, int failedIndex, int phrasesSkippedDueToFailure) {
return new DefaultTestResult(failedIndex,
phrasesSkippedDueToFailure, failingPhrase,
failureReason, testCase);
}
public static DefaultTestResult duplicateTest(TestCase testCase) {
return new DefaultTestResult(0, testCase, TechnicalReportData.Status.DUPLICATE);
}
public static DefaultTestResult passingTest(TestCase testCase) {
return new DefaultTestResult(testCase.getContextFilteredPhraseBody().size(), testCase, TechnicalReportData.Status.PASSED);
}
public TechnicalReportData.Status getStatus() {
return status;
}
public String getTestCaseTitle() {
return testCase.getTestTitle();
}
public int getPhrasesSkippedDueToFailure() {
return phrasesSkippedDueToFailure;
}
public int getPassingPhraseTotal() {
return passingPhraseTotal;
}
public Optional getFailingPhrase() {
return failingPhrase;
}
public int getTotalPhrases() {
return testCase.getContextFilteredPhraseBody().size();
}
public Optional getFailureReason() {
return failureReason;
}
@Override
public TestCase getTestCase() {
return testCase;
}
}