在 Eclipse 下使用 Maven 运行 JUnit 测试 [英] Running JUnit tests with Maven under Eclipse

查看:35
本文介绍了在 Eclipse 下使用 Maven 运行 JUnit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次在 Eclipse 上安装了插件 m2e.

I just installed the plugin m2e for the first time on Eclipse.

我编写了一个简单的 JUnit(版本 4)测试.我可以从 Eclipse 运行它,但不能从 pom.xml(alt-click,Run as,Maven Test)运行它.我想我需要告诉 Maven 搜索那个类,但我不知道如何.

I wrote a simple JUnit (version 4) test. I can run it from Eclipse, but not from the pom.xml (alt-click, Run as, Maven Test). I suppose I need to tell Maven to search for that class, but I just don't know how.

此外,我在 groupId "junit" 中找不到 JUnit 4:只有 3.8.1 版本可用.我真的需要为 3.x 版而不是 4+ 版编写测试吗?

Also, I couldn't find JUnit 4 in the groupId "junit": only the version 3.8.1 is available. Do I really need to write tests for version 3.x and not version 4+?

如何解决这个问题?

将我视为 Maven 的新手:这正是我的身份.所以请不要谈论神器技术,除非准确描述我需要做什么.我几乎无法将 Guava 安装为依赖项,现在我完全迷失了这些概念.

Think of me as a newbie with Maven: that's exactly what I am. So please don't speak about artifact technobabble unless describing exactly what I need to do. I could barely install Guava as dependency and I'm completely lost right now with these concepts.

谢谢!

推荐答案

您可以使用 Maven 运行 Junit 4.您只需要 pom 中的 Junit 4 依赖项.您还需要surefire插件来执行测试.

you can run Junit 4 with Maven. You just need the Junit 4 dependency in your pom. You also need the surefire plugin to execute the tests.

参见:http://maven.apache.org/plugins/maven-万无一失的插件/

提示:默认情况下,surefire 会查找带有 *Test.java 命名的文件来查找测试.

Hint: By default surefire looks for files with *Test.java naming to find tests.

这篇关于在 Eclipse 下使用 Maven 运行 JUnit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆