简体   繁体   English

为什么某些测试在 mvn clean install 时失败,但在我单独运行时却没有?

[英]Why some tests fail when mvn clean install but not when I run them individually?

So recently, I migrated from java 11 to 17 my project and suddenly some of my tests started to fail after executing mvn clean install command with a 500 internal error .所以最近,我从 java 11 迁移到 17 我的项目,突然我的一些测试在执行mvn clean install命令后开始失败,并出现500 internal error I wanted to debug one of the individual tests that fails to detect the problem and for my surprise when I run the command mvn -Dtest=TestClass#whenXthenY test the test passes.我想调试一个未能检测到问题的单个测试,令我惊讶的是,当我运行命令mvn -Dtest=TestClass#whenXthenY test测试通过时。

When I run mvn clean install from the IDE it works as well.当我从 IDE 运行mvn clean install时,它也可以正常工作。

I have no clue what could be happening here.我不知道这里会发生什么。 The project is a Spring Boot project.该项目是 Spring 引导项目。 Any idea what could be the reason of this behaviour?知道这种行为的原因是什么吗?

You probably have some test leakage (data being kept between tests), so the order of the tests might matter, and might be changed between the java-versions.您可能有一些测试泄漏(数据在测试之间保留),因此测试的顺序可能很重要,并且可能会在 java 版本之间更改。 This can be static variables, stuff that gets stored / loaded from disk or external services, etc. etc.这可以是 static 变量、从磁盘或外部服务存储/加载的内容等。

Do you run them in parallel?你并行运行它们吗? Else you could check if the execution order of the tests are the same or not.否则,您可以检查测试的执行顺序是否相同。

This is very hard to debug;这很难调试; the main thing is to check first if tour test are really well isolated or not.最主要的是首先检查巡回测试是否真的很好隔离。

The error was that I had two dependencies for the same thing (overlapping) and when I upgraded to Java 17 one of them wasn't working.错误是我对同一件事有两个依赖项(重叠),当我升级到 Java 17 时,其中一个不工作。

Then depending where I was running the tests from, It was taking one dependency or the other.然后取决于我从哪里运行测试,它需要一个依赖项或另一个依赖项。

I removed the redundant dependency that was not working and that fixed everything.我删除了无效的冗余依赖项并修复了所有问题。

暂无
暂无

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

相关问题 当我按包运行 mvn 测试时,JUnit 测试通过,但是当我将所有包一起运行时,一些测试失败 - JUnit tests pass when I run mvn tests by packages, but when I run all the packages together some of the tests fail 为什么我的测试一起运行时通过,但单独失败? - Why do my tests pass when run together, but fail individually? mvn clean install对于我的春季云合同消费者测试是成功的,但是当我手动运行测试时,它们失败了吗? - mvn clean install is SUCCESS for my spring-cloud-contract consumer tests, but when I run the tests manually they are FAILING? 在Eclipse中分别运行时,单元测试通过,但在mvn全新安装过程中失败 - Unit tests pass when ran separately in Eclipse but fail during mvn clean install 为什么我在运行mvn clean install时有errorRebind结果'javax.validation.ValidatorFactory'必须是一个类? - Why I have errorRebind result 'javax.validation.ValidatorFactory' must be a class when i run mvn clean install? 在“ MVN全新安装”中失败? - fail in “mvn clean install”? JUnit测试在一起运行时失败,但是单独传递 - JUnit tests fail when run together, but pass individually 连接重置错误 - 运行 mvn clean install 以运行功能时 - Connection reset error - when running mvn clean install to run features 当我在.properties文件中添加撇号时,为什么mvn clean安装失败? - Why mvn clean install fails when I put apostrophe in .properties file? 当我运行 mvn install 时出现错误 - when i run mvn install ,there is a error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM