tags:

views:

33

answers:

1

Hi all,

Time elapsed (time taken?) to run(and pass) my Junit test case is shown as 0.00. I have tried failing the test case (by doing assertEquals for a wrong value) and its still showing time elapsed as 0.00.

The rest of test cases have non-zero time elapsed values.

EDIT: Assumption - I assumed that it would surely take non-zero time to execute and that if it didn't happen, nothing was happening within the test case - example, I have a if condition in there and no corresponding else. So, if the condition failed, it just came out of the method without doing anything and since an error didn't occur, it didn't fail the test either.

Is there any reason this is happening? Am I missing something?

Thanks, Pratyusha.

A: 

It's not clear why you think it should be non-zero. Is it possible that your test case is just passing (or failing) really quickly?

Just for the sake of experimentation, put a Thread.sleep(1000) call in there... if that changes things, it suggests that everything's fine and your test is just fast.

Are all your test methods shown to be executing? It's not something simple like failing to annotate the methods or failing to keep to the naming convention of testXXX (depending on which version of JUnit you're using)?

Jon Skeet
Thanks Jon. I have tried Thread.sleep(1000) and the test is executed in a non-zero time. So it seems to be executing really fast. I assumed that it would surely take non-zero time to execute and that if it didn't happen, nothing was happening within the test case - example, I have a if condition in there and no corresponding else. So, if the condition failed, it just came out of the method without doing anything and since an error didn't occur, it didn't fail the test either.
Pratyusha