您可以在同一测试/框架中将TestNG和JUnit断言混合在一起吗? [英] Can you mix TestNG and JUnit Assertions together within the same Test / Framework?
问题描述
您可以在同一Test/Framework中将TestNG和JUnit断言混合在一起吗?
Can you mix TestNG and JUnit Assertions together within the same Test / Framework?
例如,假设我已经开发了一个框架,是否可能具有以下内容:
For example lets say I have developed a framework, is it possible to have the following:
- 使用JUNit断言的TestNG类
- 同时使用Junit和TestNG断言的TestNG吗?
感谢您的帮助
推荐答案
我认为简短的答案是否定的.如果您注意到使用@Test批注将方法标记为测试时,系统会提示您导入哪个框架.断言也是如此.考虑一下,如果提示使用Junit断言,则Testng测试将无法记录"结果.因此,在编写带有Testng @Test批注的测试时;断言自动默认为Testng断言.
I think the short answer is no. If you notice when you mark a method as a test with the @Test annotation you are prompted which framework to import. Same thing witht the assertions as well. Think about it, a Testng test wouldn't be able to 'record' a result if prompted to use a Junit assertion. Hence, when writing a test with a Testng @Test annotation; the Assertion automatically defaults to a Testng assertion.
在OP评论后更新:
Gbru检查您的\ projectFolder \ test-output \ junitreports 您要查找的xml可能已经在那里.
Gbru check your \projectFolder\test-output\junitreports the xml you are looking for might already be there..
6.2.3-JUnitReports
6.2.3 - JUnitReports
TestNG包含一个侦听器,该侦听器获取TestNG结果并输出一个XML文件,然后可以将其馈送到JUnitReport.这是一个示例,以及创建此报告的ant任务:
TestNG contains a listener that takes the TestNG results and outputs an XML file that can then be fed to JUnitReport. Here is an example, and the ant task to create this report:
<target name="reports">
<junitreport todir="test-report">
<fileset dir="test-output">
<include name="*/*.xml"/>
</fileset>
<report format="noframes" todir="test-report"/>
</junitreport>
</target>
这篇关于您可以在同一测试/框架中将TestNG和JUnit断言混合在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!