Testcase not failing even if it has actually failed

寵の児 提交于 2019-12-13 02:56:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!