[英]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.