File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
main/java/com/aventstack/extentreports/model
test/java/com/aventstack/extentreports/entity Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff 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 ());
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments