Taha Iqbal
Taha Iqbal

Reputation: 75

How to get a test's run execution time from JUnit's TestResult?

I am using org.junit.runner.JUnitCore class to run test from inside my java application. I have added my custom listener implementing org.junit.runner.notification.RunListener for reporting purpose. Currently from listener I am getting total time of all the tests by calling getRunTime() method of org.junit.runner.Result class. I want to get the (individual) method execution time.

Upvotes: 0

Views: 3464

Answers (1)

dkatzel
dkatzel

Reputation: 31648

I guess your listener can get the current time when testStarted() is called and then again get the current time when testFinished() is called. the time difference would be the amount of time the test took to run.

Upvotes: 2

Related Questions