How to use ReportConfigurationTest class of com.tngtech.jgiven.report.json package

Best JGiven code snippet using com.tngtech.jgiven.report.json.ReportConfigurationTest

Source:ReportConfigurationTest.java Github

copy

Full Screen

...14import org.junit.Test;15import org.junit.rules.TemporaryFolder;16import org.junit.runner.JUnitCore;17import org.junit.runner.Request;18public class ReportConfigurationTest extends SimpleScenarioTest<ReportConfigurationTest.ReportConfigurationTestStage> {19 @Rule20 public TemporaryFolder temporaryFolder = new TemporaryFolder();21 @Test22 public void jgiven_report_is_disabled_by_a_system_property() throws IOException {23 File reportFolder = temporaryFolder.newFolder();24 given().a_set_system_property("jgiven.report.dir", getWindowsCompatiblePath(reportFolder))25 .and().a_set_system_property("jgiven.report.enabled", "false")26 .and().a_Test_scenario();27 when().the_test_is_executed_with_junit();28 then().the_report_is_not_written_to(reportFolder);29 }30 @Test31 public void jgiven_report_directory_is_set_via_a_system_property() throws IOException {32 File reportFolder = temporaryFolder.newFolder();33 given().a_set_system_property("jgiven.report.dir", getWindowsCompatiblePath(reportFolder))34 .and().a_set_system_property("jgiven.report.enabled", "true")35 .and().a_Test_scenario();36 when().the_test_is_executed_with_junit();37 then().the_report_is_written_to(reportFolder);38 }39 private String getWindowsCompatiblePath(File file) {40 return file.getAbsolutePath().replace("\\", "/");41 }42 static class ReportConfigurationTestStage extends Stage<ReportConfigurationTestStage> {43 private TestScenarioRepository.TestScenario testScenario;44 private final Map<String, String> systemPropertiesBackup = new HashMap<>();45 @BeforeScenario46 private void createConfigurationFile() {47 a_set_system_property("jgiven.report.dir", null);48 }49 ReportConfigurationTestStage a_set_system_property(String key, String value) {50 String originalValue = System.getProperty(key);51 if (!systemPropertiesBackup.containsKey(key)) {52 systemPropertiesBackup.put(key, originalValue);53 }54 if (value == null) {55 System.clearProperty(key);56 } else {57 System.setProperty(key, value);58 }59 return self();60 }61 ReportConfigurationTestStage a_Test_scenario() {62 testScenario = new TestScenarioRepository.TestScenario(TestScenarios.class, "test_with_tag_annotation");63 return self();64 }65 ReportConfigurationTestStage the_test_is_executed_with_junit() {66 assertThat(testScenario).as("No matching test scenario found").isNotNull();67 JUnitCore junitCore = new JUnitCore();68 junitCore.run(Request.method(testScenario.testClass, testScenario.testMethod));69 return self();70 }71 ReportConfigurationTestStage the_report_is_not_written_to(File file) {72 assertThat(file).isEmptyDirectory();73 return self();74 }75 ReportConfigurationTestStage the_report_is_written_to(File file) {76 assertThat(file).isNotEmptyDirectory();77 return self();78 }79 @AfterScenario80 private void clearSystemProperties() {81 systemPropertiesBackup.entrySet()82 .stream()83 .peek(entry -> System.clearProperty(entry.getKey()))84 .filter(entry -> entry.getValue() != null)85 .forEach(entry -> System.setProperty(entry.getKey(), entry.getValue()));86 }87 }88}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JGiven automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful