-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to demonstrate the potential bug with requirements discovery
- Loading branch information
Showing
5 changed files
with
153 additions
and
40 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
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
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
112 changes: 109 additions & 3 deletions
112
...a/net/thucydides/model/requirements/reports/FileSystemRequirementsOutcomeFactoryTest.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 |
---|---|---|
@@ -1,4 +1,110 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
class FileSystemRequirmentsOutcomeFactoryTest { | ||
|
||
package net.thucydides.model.requirements.reports; | ||
|
||
import net.serenitybdd.model.di.ModelInfrastructure; | ||
import net.serenitybdd.model.environment.ConfiguredEnvironment; | ||
import net.thucydides.model.domain.ReportType; | ||
import net.thucydides.model.domain.RequirementCache; | ||
import net.thucydides.model.reports.OutcomeFormat; | ||
import net.thucydides.model.reports.TestOutcomeLoader; | ||
import net.thucydides.model.reports.TestOutcomes; | ||
import net.thucydides.model.reports.html.ReportNameProvider; | ||
import net.thucydides.model.requirements.model.Requirement; | ||
import org.junit.jupiter.api.*; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static net.thucydides.model.reports.html.ReportNameProvider.NO_CONTEXT; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class FileSystemRequirementsOutcomeFactoryTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
RequirementCache.getInstance().clear(); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() { | ||
RequirementCache.getInstance().clear(); | ||
} | ||
|
||
@Nested | ||
@DisplayName("when interpreting Serenity/JS test outcomes") | ||
class SerenityJSTestOutcomes { | ||
|
||
@Test | ||
void should_not_discover_any_additional_requirements_if_the_directory_structure_is_flat() throws IOException { | ||
|
||
List<Requirement> requirements = requirementsFrom(pathTo("serenity-js/spec-flat")); | ||
|
||
assertThat(requirements).hasSize(0); | ||
} | ||
|
||
@Test | ||
void should_treat_directories_in_a_single_level_directory_structure_as_representing_capabilities() throws IOException { | ||
|
||
List<Requirement> requirements = requirementsFrom(pathTo("serenity-js/spec-1-level")); | ||
|
||
System.out.println(requirements); | ||
|
||
assertThat(requirements).hasSize(1); | ||
|
||
Requirement capability = requirements.get(0); | ||
|
||
assertThat(capability.getType()).isEqualTo("capability"); | ||
assertThat(capability.getName()).isEqualTo("payments"); | ||
assertThat(capability.getDisplayName()).isEqualTo("Payments"); | ||
} | ||
|
||
@Test | ||
void should_treat_directories_in_a_two_level_directory_structure_as_representing_themes_and_capabilities() throws IOException { | ||
|
||
List<Requirement> requirements = requirementsFrom(pathTo("serenity-js/spec-2-levels")); | ||
|
||
System.out.println(requirements); | ||
|
||
assertThat(requirements).hasSize(2); | ||
|
||
Requirement capability = requirements.get(0); | ||
Requirement theme = requirements.get(1); | ||
|
||
assertThat(capability.getType()).isEqualTo("capability"); | ||
assertThat(capability.getName()).isEqualTo("payments"); | ||
assertThat(capability.getDisplayName()).isEqualTo("Payments"); | ||
|
||
assertThat(theme.getType()).isEqualTo("theme"); | ||
assertThat(theme.getName()).isEqualTo("ecommerce"); | ||
assertThat(theme.getDisplayName()).isEqualTo("Ecommerce"); | ||
} | ||
} | ||
|
||
private List<Requirement> requirementsFrom(Path exampleRootDirectory) throws IOException { | ||
|
||
Path requirementsDirectory = exampleRootDirectory.resolve("spec"); | ||
Path jsonOutcomesDirectory = exampleRootDirectory.resolve("outcomes"); | ||
|
||
final FileSystemRequirementsOutcomeFactory requirmentsOutcomeFactory = new FileSystemRequirementsOutcomeFactory( | ||
ConfiguredEnvironment.getEnvironmentVariables(), | ||
ModelInfrastructure.getIssueTracking(), | ||
new ReportNameProvider( | ||
NO_CONTEXT, | ||
ReportType.HTML, | ||
null // requirementsService; not needed in this context | ||
), | ||
requirementsDirectory.toString()); | ||
|
||
TestOutcomes outcomes = TestOutcomeLoader.loadTestOutcomes() | ||
.inFormat(OutcomeFormat.JSON) | ||
.from(jsonOutcomesDirectory.toFile()) | ||
.withRequirementsTags(); | ||
|
||
return requirmentsOutcomeFactory.buildRequirementsOutcomesFrom(outcomes).getRequirements(); | ||
} | ||
|
||
private static Path pathTo(String resource) { | ||
return new File(ClassLoader.getSystemClassLoader().getResource(resource).getFile()).toPath(); | ||
} | ||
} |
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