如何确保在使用maven失败的jUnit测试后进行清理?(How to ensure cleanup after failed jUnit tests using maven?)
编辑在底部添加更多信息
我在这里看过: 在单元测试之后,maven / surefire需要清理的一种好方法是否合格? 但它不能帮助我。 我可能会错误地配置故障安全和/或保证。
我有依赖于配置文件的jUnit测试,并且我在process-test-resources阶段添加了copy-rename-maven-plugin来为jUnit测试设置配置文件的测试副本,在后期集成测试阶段重命名maven-plugin和maven-clean-plugin,将所有事情恢复到原来的状态。 但是,当jUnit测试失败时,后续阶段没有运行,即使我也有失败安全插件。
故障安全文档中的jUnit示例都使用surefire,所以我对如何获得故障安全来运行它们感到困惑 - 或者甚至是我需要做的。
我已经将jUnit声明为依赖项
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency>
我在构建中使用了失败安全插件:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.20</version> <!-- <configuration> <skipITs>true</skipITs> </configuration> --> <executions> <execution> <id>run-nonautowired-tests</id> <phase>integration-test</phase> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <includes> <include>*Test.java</include> </includes> </configuration> </execution> </executions> </plugin>
我没有遵循* IT命名约定的任何集成测试,只有遵循* Test命名约定的jUnit测试。 我只是试图使用故障安全来确保我的清理完成。 我已经试过skipITs,我试过评论。 我试过了,没有配置包含。
我目前已经将surefire插件注释掉了,但它仍然在运行测试并且失败了构建,这取决于我看到的输出结果:
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> -->
我错过了什么/做错了什么? 看起来我以前有过这样的工作,但它在使用Spring的另一个项目中运行了两次jUnit测试,在那里我需要添加不使用Spring的测试 - 但我不记得我做了什么不同。
我在IntelliJ 14.1.5中这样做,但是将Maven生命周期运行到验证阶段,而不是让IntelliJ直接运行jUnit测试。
另外,它似乎是运行默认测试的surefire 2.12.4,我不知道它是从哪里来的。
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project RefRange: There are test failures.
我应该在哪里看到2.12.4来自哪里? 我怎样才能得到这个运行一次jUnit测试,并继续到下一个阶段,即使他们失败了?
谢谢你的帮助,
Rebeccah
附加信息:取消注释我的surefire插件后,添加
<skip>false</skip> <skipTests>true</skipTests>
到它的配置,改变故障安全包括到
<includes>**/*Test.java</includes>,
并运行mvn verify -X,我在故意测试失败后立即得到以下内容:
[INFO] Results: [INFO] [ERROR] Failures: [ERROR] ref_range_by_RTest.testGetConfigManager:56 Expected: is "C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 8.0.27/app_rsrcs/refrange/data" but: was "C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 8.0.27/app_rsrcs/refrange/data-not" [INFO] [ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0 [INFO] [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting. outputEncoding}. [INFO] [INFO] --- maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) @ RefRange --- [DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:2.20, parent: sun.misc.Launcher$AppClassLoader@647e05] [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify' with basic configurator --> [DEBUG] (s) basedir = C:\Git\clincor-clindev\refrange [DEBUG] (s) reportsDirectory = C:\Git\clincor-clindev\refrange\target\failsafe-reports [DEBUG] (s) skip = false [DEBUG] (f) summaryFile = C:\Git\clincor-clindev\refrange\target\failsafe-reports\failsafe-summary.xml [DEBUG] (s) testClassesDirectory = C:\Git\clincor-clindev\refrange\target\test-classes [DEBUG] (s) testFailureIgnore = false [DEBUG] (f) session = org.apache.maven.execution.MavenSession@2eef62 [DEBUG] -- end configuration -- [DEBUG] Failsafe report directory: C:\Git\clincor-clindev\refrange\target\failsafe-reports [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.976 s [INFO] Finished at: 2017-05-17T20:54:09-07:00 [INFO] Final Memory: 17M/247M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures. [ERROR] [ERROR] Please refer to C:\Git\clincor-clindev\refrange\target\failsafe-reports for the individual test results. [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream. [ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures.
Editing to add additional information at the bottom
I've looked here: What is a good way in maven/surefire to clean up after unit tests, whether they pass or not? but it's not helping me. I'm probably configuring failsafe and/or surefire incorrectly.
I have jUnit tests that depend on configuration files being in place, and I've added copy-rename-maven-plugin in the process-test-resources phase to set up test copies of the config files for the jUnit tests, and copy-rename-maven-plugin and maven-clean-plugin in the post-integration-test phase to restore everything back the way it was when I'm done. But when the jUnit tests fail, the subsequent phases aren't running, even though I have failsafe plugin as well.
The jUnit examples in the failsafe documentation all use surefire, so I'm confused about how to get failsafe to run them - or if that's even what I need to do.
I've got jUnit declared as a dependency
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency>
I've got failsafe plugin in the build:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.20</version> <!-- <configuration> <skipITs>true</skipITs> </configuration> --> <executions> <execution> <id>run-nonautowired-tests</id> <phase>integration-test</phase> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <includes> <include>*Test.java</include> </includes> </configuration> </execution> </executions> </plugin>
I don't have any integration tests following the *IT naming conventions, only the jUnit tests following the *Test naming conventions. I'm just trying to use failsafe as a way to ensure my cleanup gets done. I've tried skipITs true and I've tried commenting that out. I've tried with and without the configuration includes.
I've currently got surefire plugin commented out, but it's still running the tests and failing the build, based on the output I'm seeing:
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> -->
What am I missing/doing wrong? It seems I had this working before, but it was running the jUnit tests twice in a different project that used Spring, where I needed to add tests that didn't use Spring - but I can't remember what I did differently.
I'm doing this inside IntelliJ 14.1.5, but running the Maven Lifecycle to the verify phase rather than having IntelliJ run the jUnit tests directly.
Also, it seems that its surefire 2.12.4 that is running the default-test, and I have no idea where that is coming from.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project RefRange: There are test failures.
Where should I look to see where 2.12.4 is coming from? And how can I get this to run the jUnit tests once, and continue on to the next phase even if they fail?
Thanks for any help,
Rebeccah
Additional information: After uncommenting my surefire plugin, adding
<skip>false</skip> <skipTests>true</skipTests>
to its configuration, changing the failsafe includes to
<includes>**/*Test.java</includes>,
and running mvn verify -X, I get the following immediately after my intentional test failure:
[INFO] Results: [INFO] [ERROR] Failures: [ERROR] ref_range_by_RTest.testGetConfigManager:56 Expected: is "C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 8.0.27/app_rsrcs/refrange/data" but: was "C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 8.0.27/app_rsrcs/refrange/data-not" [INFO] [ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0 [INFO] [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! The file encoding for reports output files should be provided by the POM property ${project.reporting. outputEncoding}. [INFO] [INFO] --- maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) @ RefRange --- [DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:2.20, parent: sun.misc.Launcher$AppClassLoader@647e05] [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify' with basic configurator --> [DEBUG] (s) basedir = C:\Git\clincor-clindev\refrange [DEBUG] (s) reportsDirectory = C:\Git\clincor-clindev\refrange\target\failsafe-reports [DEBUG] (s) skip = false [DEBUG] (f) summaryFile = C:\Git\clincor-clindev\refrange\target\failsafe-reports\failsafe-summary.xml [DEBUG] (s) testClassesDirectory = C:\Git\clincor-clindev\refrange\target\test-classes [DEBUG] (s) testFailureIgnore = false [DEBUG] (f) session = org.apache.maven.execution.MavenSession@2eef62 [DEBUG] -- end configuration -- [DEBUG] Failsafe report directory: C:\Git\clincor-clindev\refrange\target\failsafe-reports [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.976 s [INFO] Finished at: 2017-05-17T20:54:09-07:00 [INFO] Final Memory: 17M/247M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures. [ERROR] [ERROR] Please refer to C:\Git\clincor-clindev\refrange\target\failsafe-reports for the individual test results. [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream. [ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (run-nonautowired-tests) on project RefRange: There are test failures.
原文:https://stackoverflow.com/questions/44035853
最满意答案
据我了解你的帖子,你发送消息到不属于你的应用程序的窗口。 如果是这样,那么恐怕你必须在每次SendKeys呼叫之前检查活动窗口。
As far as I understand from your post you send messages to windows that do not belong to your application. If so, then I'm afraid you have to check active window before every SendKeys call.
相关问答
更多-
使用其IP和端口号Telnet您的数据库。 Telnet your DB with its ip and the port number.
-
你总是可以尝试更多的线路来禁用计算和警报等。 Application.ScreenUpdating = false Application.Calculations = xlManual Application.DisplayAlerts = False 但是,如果你真的想绕过所有背景废话excel似乎不通过一个循环直接访问表,这个概念可能会棘手,如果你不习惯它,但它的价值每一点,并会加快你的代码如此之快会奇怪你为什么从来没有做到这一点。 我没有让你的代码生病,只是举例说明它是如何工作的 Dim Rang ...
-
检查应用程序是否在运行或哪个选项卡处于活动状态(Checking whether the application in running or which tab is active)[2022-08-03]
获取运行过程并定期检查它们,找到活动过程并计算时间。 MSDN页面 博客 并在第一位使用Google! Get the running process and check them periodically, find the active process and calculate the time. MSDN page blog And use Google in fist place! -
当您的应用程序激活时,它将成为最上面的窗口。 IOW,它跳转到最高Z位置。 有了这个,之前的最上面的窗口被降到“刚刚在新的最上面的窗口下面”的位置。 IOW,它在Z顺序位置成为第二位。 调用GetNextWindow并将它传递给表单的句柄和GW_HWNDNEXT可能会给你你需要的结果。 When your application activates, it becomes the topmost window. IOW, it jumps to the top Z-order position. With ...
-
Sencha Touch(以及代理和基于Web的框架)无法作为“本机”Windows XP / 7桌面应用程序运行,除非您使用此工具编译它。 Sencha曾经有一个桌面打包器,但已停止使用 - 这里列出了替代品。 我只使用Cordova / PhoneGap用于移动应用程序,但根据他们的网站,它确实支持编译到Windows桌面。 另一种选择是构建Chrome打包应用(在Chrome浏览器中运行,但可以分发)。 最后,Windows 8应用程序可以使用JavaScript本地编写 - 但这仅适用于Win8,而 ...
-
主动窗口检测(Active window detection)[2023-05-23]
您可以使用window.onfocus和window.onblur代替那段代码。 它受到所有主流浏览器的支持,可以完美地满足您的需求。 例如,它会检测您更改选项卡的时间,或者按照您的说明打开另一个应用程序。 例: window.onfocus = function() { console.log('Focused'); }; window.onblur = function() { console.log('Not focused'); }; You could use window.o ... -
通过在Game类的实现中使用IsActive(默认情况下称为Game1),可以避免在游戏未对焦时接收输入。 protected override void Update(GameTime gameTime) { base.Update(gameTime); if (!IsActive) { return; } // ... do regualr update. } http://msdn.microsoft.com/en-us/library/m ...
-
据我了解你的帖子,你发送消息到不属于你的应用程序的窗口。 如果是这样,那么恐怕你必须在每次SendKeys呼叫之前检查活动窗口。 As far as I understand from your post you send messages to windows that do not belong to your application. If so, then I'm afraid you have to check active window before every SendKeys call.
-
不幸的是,这是不可能的,因为AIR既不能访问流程信息也不能访问系统性能指标。 您唯一的希望是在.NET或Objective C中创建另一个服务(例如,不是跨平台 - 假设这是一个要求),它可以通过本地NetConnection向AIR应用程序提供流程信息。 我不确定Java,但你可能能够逃脱Mono。 Unfortunately this isn't possible, since AIR can access neither process information nor system performan ...
-
在阅读了很多内容后,我将代码分为两种情况,分别用于metro应用程序和所有其他应用程序。 我的解决方案处理了我为metro应用程序获得的异常以及我对该平台的异常。 这是最终有效的代码: [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern ...