简体   繁体   English

如何在拼写错误的dataprovider上进行testng测试失败?

[英]how to fail testng test on misspelled dataprovider?

testNg binds data providers by name (a string). testNg按名称(字符串)绑定数据提供者。 when i misspelled it, it returned success. 当我拼错它时,它返回了成功。 just no tests were run. 只是没有运行测试。 is there any configuration option to fail-fast in case of such error? 是否有任何配置选项可以在发生此类错误时快速故障切换?

Actually, when a test case does not find its data provider (which happens in your case of misspelled data provider name), that test case is skipped. 实际上,当一个测试用例找不到其数据提供者时(在您的数据提供者名称拼写错误的情况下发生),该测试用例将被跳过。 And therefore, no test is run. 因此,没有运行测试。 What you need is a way to see skipped test cases. 您需要的是一种查看跳过的测试用例的方法。

You can print messages or throw exceptions whenever a test is skipped. 每当跳过测试时,您都可以打印消息或引发异常。 However, throwing exceptions may not be recommended because it may stop build after the first skipped tests and your entire test suite may remain untested. 但是,可能不建议抛出异常,因为它可能会在第一次跳过测试后停止构建,并且整个测试套件可能仍未经测试。

Approach 1 You need to implement ITestListener which provides method 方法1您需要实现提供方法的ITestListener

   onTestSkipped(ITestResult testResult)

Approach 2 TestNG also enables you to generate reports at the end of test run. 方法2通过 TestNG,还可以在测试运行结束时生成报告。 You need to implement 您需要实施

 IReporter interface

You need to code for generateReport() method. 您需要为generateReport()方法进行编码。

In addition for both the above approaches, you need to configure your implementation class as a listener in testng.xml like following. 上述两种方法外,您还需要像下面这样在testng.xml中将实现类配置为侦听器。

<listeners>
    <listener class-name="com...test.reporter.TestStatusReporter" />
</listeners>

Next Once you run 下一步一旦运行

mvn install 

and is successful, you can view test results including skipped tests details in the following location of your project. 成功完成后,您可以在项目的以下位置查看测试结果,包括跳过的测试详细信息。

../target/surefire-reports/index.html

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM