Skip to content

Commit 95caba9

Browse files
committed
#247 add tests
1 parent be749c5 commit 95caba9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/com/aventstack/extentreports/model/Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public final long timeTaken() {
177177
*
178178
* Solution provided by @grasshopper7
179179
* https://github.com/extent-framework/extentreports-java/issues/247#issuecomment-679918613
180+
*
181+
* @return A formatted time taken string as HH:mm:ss:SSS
180182
*/
181183
public final String timeTakenPretty() {
182184
Date date = new Date(timeTaken());

src/test/java/com/aventstack/extentreports/entity/TestEntityTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,30 @@ public void timeTaken() {
318318
long duration = test.timeTaken();
319319
Assert.assertTrue(duration < 5);
320320
}
321+
322+
@org.testng.annotations.Test
323+
public void timeTakenPretty() {
324+
Test test = getTest();
325+
String duration = test.timeTakenPretty();
326+
String[] durationParts = duration.split(":");
327+
Assert.assertEquals(durationParts[0], "00");
328+
Assert.assertEquals(durationParts[1], "00");
329+
Assert.assertEquals(durationParts[2], "00");
330+
long millis = Integer.parseInt(durationParts[3]);
331+
Assert.assertTrue(millis >= 0);
332+
}
333+
334+
@org.testng.annotations.Test
335+
public void timeTakenPrettyWithLog() throws InterruptedException {
336+
Test test = getTest();
337+
Thread.sleep(10);
338+
test.addLog(Log.builder().status(Status.PASS).build());
339+
String duration = test.timeTakenPretty();
340+
String[] durationParts = duration.split(":");
341+
Assert.assertEquals(durationParts[0], "00");
342+
Assert.assertEquals(durationParts[1], "00");
343+
Assert.assertEquals(durationParts[2], "00");
344+
long millis = Integer.parseInt(durationParts[3]);
345+
Assert.assertTrue(millis > 0);
346+
}
321347
}

0 commit comments

Comments
 (0)