首页 \ 问答 \ 如何确保在使用maven失败的jUnit测试后进行清理?(How to ensure cleanup after failed jUnit tests using maven?)

如何确保在使用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
更新时间:2023-12-03 13:12

最满意答案

据我了解你的帖子,你发送消息到不属于你的应用程序的窗口。 如果是这样,那么恐怕你必须在每次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.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)