88import com .aventstack .extentreports .gherkin .GherkinDialectManager ;
99import com .aventstack .extentreports .gherkin .model .Feature ;
1010import com .aventstack .extentreports .model .Test ;
11+ import org .testng .annotations .BeforeMethod ;
1112
1213public class ExtentReportsTest {
14+
1315 private static final String TEST_NAME = "TEST" ;
16+ private ExtentReports extent ;
1417
15- private ExtentReports extent () {
16- return new ExtentReports ();
18+ @ BeforeMethod
19+ public void beforeMethod () throws UnsupportedEncodingException {
20+ extent = new ExtentReports ();
21+ extent .setGherkinDialect ("en" );
1722 }
1823
1924 @ org .testng .annotations .Test
2025 public void createTestOverloadTypeNameDesc () {
21- ExtentTest test = extent () .createTest (Feature .class , TEST_NAME , "Description" );
26+ ExtentTest test = extent .createTest (Feature .class , TEST_NAME , "Description" );
2227 Test model = test .getModel ();
2328 Assert .assertTrue (model .isBDD ());
2429 Assert .assertEquals (model .getName (), TEST_NAME );
@@ -29,7 +34,7 @@ public void createTestOverloadTypeNameDesc() {
2934
3035 @ org .testng .annotations .Test
3136 public void createTestOverloadTypeName () {
32- ExtentTest test = extent () .createTest (Feature .class , TEST_NAME );
37+ ExtentTest test = extent .createTest (Feature .class , TEST_NAME );
3338 Test model = test .getModel ();
3439 Assert .assertTrue (model .isBDD ());
3540 Assert .assertEquals (model .getName (), TEST_NAME );
@@ -40,7 +45,7 @@ public void createTestOverloadTypeName() {
4045
4146 @ org .testng .annotations .Test
4247 public void createTestOverloadKeywordNameDesc () throws ClassNotFoundException {
43- ExtentTest test = extent () .createTest (new GherkinKeyword ("Feature" ), TEST_NAME , "Description" );
48+ ExtentTest test = extent .createTest (new GherkinKeyword ("Feature" ), TEST_NAME , "Description" );
4449 Test model = test .getModel ();
4550 Assert .assertTrue (model .isBDD ());
4651 Assert .assertEquals (model .getName (), TEST_NAME );
@@ -51,7 +56,7 @@ public void createTestOverloadKeywordNameDesc() throws ClassNotFoundException {
5156
5257 @ org .testng .annotations .Test
5358 public void createTestOverloadKeywordName () throws ClassNotFoundException {
54- ExtentTest test = extent () .createTest (new GherkinKeyword ("Feature" ), TEST_NAME );
59+ ExtentTest test = extent .createTest (new GherkinKeyword ("Feature" ), TEST_NAME );
5560 Test model = test .getModel ();
5661 Assert .assertTrue (model .isBDD ());
5762 Assert .assertEquals (model .getName (), TEST_NAME );
@@ -62,7 +67,7 @@ public void createTestOverloadKeywordName() throws ClassNotFoundException {
6267
6368 @ org .testng .annotations .Test
6469 public void createTestOverloadNameDesc () {
65- ExtentTest test = extent () .createTest (TEST_NAME , "Description" );
70+ ExtentTest test = extent .createTest (TEST_NAME , "Description" );
6671 Test model = test .getModel ();
6772 Assert .assertFalse (model .isBDD ());
6873 Assert .assertEquals (model .getName (), TEST_NAME );
@@ -73,7 +78,7 @@ public void createTestOverloadNameDesc() {
7378
7479 @ org .testng .annotations .Test
7580 public void createTestOverloadName () {
76- ExtentTest test = extent () .createTest (TEST_NAME );
81+ ExtentTest test = extent .createTest (TEST_NAME );
7782 Test model = test .getModel ();
7883 Assert .assertFalse (model .isBDD ());
7984 Assert .assertEquals (model .getName (), TEST_NAME );
@@ -84,15 +89,13 @@ public void createTestOverloadName() {
8489
8590 @ org .testng .annotations .Test
8691 public void gherkinDialect () throws UnsupportedEncodingException {
87- ExtentReports extent = extent ();
8892 extent .setGherkinDialect ("de" );
8993 Assert .assertEquals (GherkinDialectManager .getLanguage (), "de" );
9094 }
9195
9296 @ org .testng .annotations .Test
9397 public void addTestRunnerOutputSingle () {
9498 String [] logs = new String []{"Log1" , "Log2" };
95- ExtentReports extent = extent ();
9699 Arrays .stream (logs ).forEach (extent ::addTestRunnerOutput );
97100 Assert .assertEquals (extent .getReport ().getLogs ().size (), 2 );
98101 Arrays .stream (logs ).forEach (x -> Assert .assertTrue (extent .getReport ().getLogs ().contains (x )));
@@ -101,7 +104,6 @@ public void addTestRunnerOutputSingle() {
101104 @ org .testng .annotations .Test
102105 public void addTestRunnerOutputList () {
103106 String [] logs = new String []{"Log1" , "Log2" };
104- ExtentReports extent = extent ();
105107 extent .addTestRunnerOutput (Arrays .asList (logs ));
106108 Assert .assertEquals (extent .getReport ().getLogs ().size (), 2 );
107109 Arrays .stream (logs ).forEach (x -> Assert .assertTrue (extent .getReport ().getLogs ().contains (x )));
0 commit comments