-1

I am noticing that JUnit (on Eclipse Indigo at least) is reporting the time of each test, including the @Before and @After setup and tear down functions.

I'd like to only see the time it takes the individual @Test functions to run, sans the overhead setup and teardown.

Don't get me wrong, I can see why including the setup and tear down can be important, but for my purposes, separating them would be more beneficial.

These tests really ought to take a matter of milliseconds. Hopefully I can do this without having to write my own/use Apache stopwatch function!

// Using JUnit 4, Java 6, Eclipse Indigo

Could there be a way to overload/override the JUnit reported time of test run with a manual #?

UPDATE:

It appears the timing of the function is in private methods found here: https://github.com/junit-team/junit/blob/72af03c49fdad5f10e36c7eb4e7045feb971d253/src/main/java/org/junit/runner/Result.java

Since they aren't protected, I don't think we can override the start and stop times...

E.S.
  • 2,733
  • 6
  • 36
  • 71
  • A simple Bump would suffice to remind me back here, @Wirus. Anyway, I found a partial answer through solving this issue here: http://stackoverflow.com/a/18156294/1582712. Essentially, when you overload the `@Before` and `@After` methods, it will over load them after the default @Before and @After methods run, allowing you to record more precise time. However, I am not yet sure how to put that new time int he Eclipse/Ant unit testing time record... – E.S. Aug 10 '13 at 20:03

1 Answers1

0

You can include a time stamp as the first line in your @Test functions, and another time stamp as the last line in the @Test functions. A simple calculation of the difference between the two times would show how long the test itself take without the setup and tear down parts.

Caren
  • 1,358
  • 2
  • 13
  • 22