问题
I use TestNG and its dataProvider mechanism to run testcases. I run the TCs parallely. I have a single Test method and that method calls the actual testcase logic defined in some other class using reflection.
The testcase logic written in the other class does not have any @Test annotation over its methods.
Now whenever any testcase case throws any exception I catch Exception and then
Assert.fail();
But in the testNG report it says failed=0 even after some TCs fail.
Why the TC is not failing ??
please help.
回答1:
There was a problem in my code. I was calling all the methods defined specifically for testcases using reflection. And the actual logic of test case was there in the method being called via reflection. And I was trying to use Assert.fail()
from there. So the testcase was not getting failed, as the method is not a test as per TestNG, as the method did not have any @Test
annotation.
I threw a custom exception from all those test methods of mine. And then caught them in the actual test which calls these methods using reflection and there I user the Assert.fail()
and now the Test Cases are failing properly.
来源:https://stackoverflow.com/questions/19152560/testcase-not-failing-even-if-it-has-actually-failed