英文:
Run All JUnit Tests VSCode
问题
我已经能够将 JUnit 5 添加到 VSCode,并在单个文件上运行测试,但我希望能够使用测试资源管理器窗格中的“运行所有测试”按钮,以便能够一次运行所有测试。然而,我遇到了一个问题,当我按下此按钮时,在输出中出现以下错误:
错误:无法解析 JUnit 启动参数
我认为我需要添加某种启动配置来传递参数给 JUnit,但我尚未找到任何关于如何实现此目的的信息。是否有人了解如何使此功能正常工作?
英文:
I've been able to add JUnit 5 to VSCode and run tests on single files, but I'd like to be able to use the 'Run all tests' button in the test explorer pane so that I can get all tests to run at once. However, i'm encountering a problem where when I press this button and I get the following error in output:
Error: Failed to parse the JUnit launch arguments
I think I need to add some kind of launch configuration to pass in arguments to JUnit, but I've not been able to find anything about how to do this. Does anyone have any insight into getting this to work?
答案1
得分: 2
我最终解决了这个问题。对于任何找到这个的人,诀窍是要确保在类声明上方添加 @Testable
注解。这将允许 JUnit 在测试资源管理器中点击“运行所有测试”按钮时找到这些测试。之前,我只在方法声明上方使用 @Test
注解,这对于自动发现测试是不够的。
示例代码:
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
import org.junit.platform.commons.annotation.Testable;
@Testable
public class FooTest {
@Test
public void testIfTrue() {
assertTrue(false);
}
}
英文:
I worked this out eventually. For anyone who finds this, the trick is to make sure you add the @Testable
annotation above the class declaration. This will allow JUnit to find the tests when you click the run all tests button in the test explorer. Previously I was only using the @Test
annotation above method declarations which is not sufficient for auto discovery of tests.
Example code:
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
import org.junit.platform.commons.annotation.Testable;
@Testable
public class FooTest {
@Test
public void testIfTrue() {
assertTrue(false);
}
}
答案2
得分: 0
我遇到了相同的情况。而且现有的答案对我的情况没有起作用。尽管出于相同的原因已经解决了,但我仍然想知道这是怎么发生的...
关于我的情况,是因为 Junit 在 VScode 中突然无法工作,并显示了一些错误。
错误:无法解析 JUnit 启动参数 #936 中提供的建议似乎很有用,但对我没用。
在 Junit 再次工作之前,我执行的最后两步是,我首先构建了工作区构建工作区两次,分别选择了完整构建和增量构建。然后,我通过 VS Code 菜单 创建了一个新文件并复制了代码。然后,它突然之间就可以工作了...
希望这可以帮助到您。
英文:
I came across the same situation. And the existing answer didn't work for m situation. Although it has been sovled for same reason, I am still wondering how this happen...
As for my situation, it was that the Junit didn't work suddenly in VScode and it showed the some Error.
The advice given in Error: Failed to parse the JUnit launch arguments #936 seems to be useful, but didn't work for me.
The final two step I did before Junit works again are that I first build workspace build workspace for two times, choosing full and incremental respectively. And then I create a new file through VS code menu and copy the code. And it suddenly works...
Hope it can help.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论