Java 如何将 TestNG 测试输出文件夹配置为 Maven 目标文件夹内?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22996542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to config TestNG test-output folder to be inside Maven target folder?
提问by helenov
Folks!
伙计们!
I'm new on TestNG, and I'm trying it with Maven (Surefire plugin) and Eclipse.
我是 TestNG 的新手,我正在尝试使用 Maven(Surefire 插件)和 Eclipse。
When my tests are run by Maven its reports are put on target/surefire-reports as expected, but the same tests when run by Eclipse TestNG plugin I'd like them to be put inside a target subfolder also (and as so be cleaned by clean Maven goal and ignored by git, not saying about respecting Maven folder organization), but always go to the default ${basedir}/test-output.
当我的测试由 Maven 运行时,它的报告按预期放在目标/surefire-reports 上,但是由 Eclipse TestNG 插件运行时相同的测试我希望它们也放在目标子文件夹中(并且因此被清理清洁 Maven 目标并被 git 忽略,而不是说尊重 Maven 文件夹组织),但始终转到默认的 ${basedir}/test-output。
There is a way I can do it? I'd prefer one that I do not need to manually config Eclipse settings (Couldn't TestNG in detect it's a Maven project and so change its output folder consistently?), but if there is no such way, anyone surely will help.
有办法吗?我更喜欢不需要手动配置 Eclipse 设置的设置(无法通过 TestNG 检测到它是一个 Maven 项目,因此一致地更改其输出文件夹?),但如果没有这种方法,任何人肯定会提供帮助。
TIA and regards,
TIA 和问候,
Heleno
海伦诺
采纳答案by niharika_neo
There is a no way that testng plugin can automatically figure out.
testng插件无法自动找出。
You can set your testng preferences at the workspace or project level. If you set it at the workbench level then for all projects, by default, testng would put the results there.
您可以在工作区或项目级别设置测试首选项。如果您在工作台级别设置它,那么对于所有项目,默认情况下,testng 会将结果放在那里。
Go to Window->Prefs->TestNG.
Change Output directory to be same as maven output directory.
转到窗口->首选项->TestNG。
将输出目录更改为与 Maven 输出目录相同。
回答by Monis Majeed
You will need to reconfigure XML Reporter as described at http://testng.org/doc/documentation-main.html#logging-xml-reportsto set the outputDirectory
property.
您需要按照http://testng.org/doc/documentation-main.html#logging-xml-reports 中的说明重新配置 XML Reporter以设置该outputDirectory
属性。
From that page:
从该页面:
In order to configure this reporter you can use the -reporter option in the command line or the Ant task with the nested element. For each of these you must specify the class org.testng.reporters.XMLReporter. Please note that you cannot configure the built-in reporter because this one will only use default settings. If you need just the XML report with custom settings you will have to add it manually with one of the two methods and disable the default listeners.
为了配置这个报告器,您可以在命令行或带有嵌套元素的 Ant 任务中使用 -reporter 选项。对于其中的每一个,您必须指定类 org.testng.reporters.XMLReporter。请注意,您无法配置内置报告器,因为该报告器仅使用默认设置。如果您只需要带有自定义设置的 XML 报告,则必须使用两种方法之一手动添加它并禁用默认侦听器。
It isn't clear how this translates into a configuration for the Maven Surefire plugin.
目前尚不清楚这如何转化为 Maven Surefire 插件的配置。
回答by Vivek Singh
You can follow the way that niharika_neo told... Elsewise you can also create timestamp enabled folder that would be created for every maven run you do, so won't let your testng reports bother you much. If still bothering put testng reports to a specific folder.
您可以按照 niharika_neo 所说的方式进行操作……另外,您还可以创建启用时间戳的文件夹,该文件夹将为您执行的每次 maven 运行创建,因此不会让您的 testng 报告打扰您。如果仍然打扰将 testng 报告放在特定文件夹中。
You can provide a different folder in your pom as --
你可以在你的 pom 中提供一个不同的文件夹——
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
</properties>
and under configuration of your maven-surefire-plugin put --
并在您的 maven-surefire-plugin 配置下放置-
<reportsDirectory>./test-output/${timestamp}</reportsDirectory>
回答by rayk
I had the same issue and I resolved it by going to Window-> Preferences -> TestNG From there I check marked Absolute output path and entered the absolute path in the Output directory. For example C:\TestResults
我遇到了同样的问题,我通过转到 Window-> Preferences -> TestNG 解决了它。从那里我检查了标记的绝对输出路径并在输出目录中输入了绝对路径。例如 C:\TestResults