标签: surefire

Surefire没有接受Junit 4测试

出于某种原因,我无法获得Maven 2 Surefire插件来执行JUnit 4测试类.

public class SimpleTest {
  @org.junit.Test
  public void simple() {
     System.out.println("foo");
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我将此类更改为JUnit-3,例如

public class SimpleTest extends junit.framework.TestCase {
  public void testBar() {
     System.out.println("bar");
  }

  @org.junit.Test
  public void simple() {
     System.out.println("foo");
  }
}
Run Code Online (Sandbox Code Playgroud)

然后它被执行.这就是我所做的:

  • 已验证的Maven版本:Apache Maven 2.2.1(r801777; 2009-08-06 20:16:01 + 0100)
  • 经过验证的Surefire版本:遵循建议
  • 经过验证的Surefire版本:检查了我的Surefire罐子~/.m2/repository/org/apache/maven/surefire- 所有这些都是版本2.4.2或2.4.3
  • 做了一个mvn dependency:tree | grep junit以确保我只依赖junit 4.7版

我遇到此问题的模块没有JUnit 3测试.

还有什么我想念的吗?

java maven-2 surefire maven

35
推荐指数
7
解决办法
5万
查看次数

Junit maven在启动fork时发生错误,检查日志中的输出

BUILD ERROR启动fork时发生错误,使用maven 2.2.1和surefire插件2.11检查日志输出,同时运行junit测试用例

maven-2 maven-plugin surefire maven

30
推荐指数
1
解决办法
2万
查看次数

如何从maven传递java代码参数进行测试

我需要传递以下价值观......

exeEvironment (测试环境), testGroup(testNG中的组)

从命令行 - > POM - > TestNG - >测试用例.

基于这两个帖子......

从maven传递一个java参数

如何从Surefire Maven插件传递参数到guicified TestNG测试?

我做了以下配置..

surefire插件中,我尝试了两个选项,似乎都没有.

=====

(1)

  <execution>
<id>default-test</id>
    <goals>
        <goal>test</goal>
    </goals>
    <configuration>
        <properties>
            <exeEnvironment>${exeEnvironment}</exeEnvironment>
            <testGroup>${testGroup}</testGroup>
        </properties>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)

(2)

<execution>
<id>default-test</id>
<goals>
    <goal>test</goal>
</goals>
<configuration>
    <systemPropertyVariables> <exeEnvironment>${exeEnvironment}</exeEnvironment> 
        <testGroup>${testGroup}</testGroup> </systemPropertyVariables> 
    <suiteXmlFiles>
        <suiteXmlFile>testng.xml</suiteXmlFile>
    </suiteXmlFiles>
</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)

testNG.xml中,我可以使用testGroup像...这样的变量吗?

<test name="Web Build Acceptance">
    <groups>
        <run>
            <include name="${testGroup} />
        </run>
    </groups>
    <classes>
        <class name="com.abc.pqr" />
    </classes>
</test> …
Run Code Online (Sandbox Code Playgroud)

testng command-line surefire pom.xml maven

28
推荐指数
2
解决办法
8万
查看次数

有没有办法告诉surefire跳过某个包中的测试?

像下面这样的东西.

我想要一种方法来跳过我的dao测试.试图避免定义套件的开销.

使用CI,我希望每晚有一个运行所有测试,另一个5分钟的SCM调查仅运行"快速"测试.

mvn -DskipPattern=**.dao.** test
Run Code Online (Sandbox Code Playgroud)

maven-2 surefire

27
推荐指数
3
解决办法
2万
查看次数

如何更轻松地调试maven surefire测试(使用eclipse作为调试服务器)

我正在使用maven/surefire/eclipse编写一些代码,然后再进行测试/调试.

标准方法是使用maven.surefire.debug maven属性.默认情况下,启用此属性后,maven将开始侦听端口5005,并且我可以使用远程调试器附加到已调试的进程.当测试完成远程调试器与服务器的连接时.

在eclipse中使用时,此过程涉及两个步骤:

  1. 跑maven
  2. 使用远程启动配置连接

我想要实现的是将其减少为:

  1. 跑maven

我发现,将maven.surefire.debug属性设置为某些远程调试选项将改变远程调试行为.因此,当我指定ie

-Dmaven.surefire.debug =" - Xdebug -Xrunjdwp:transport = dt_socket,server = n,address = 5005"

然后build将尝试连接到我的eclipse进程,监听端口5005.这样我就可以反转maven和eclipse的默认客户端/服务器角色.

然而,这种方法存在一个大问题.它没有给我任何东西,因为在maven构建完成后,eclipse停止在服务器端口上侦听.这是我不理解的部分.当我作为调试客户端从eclipse连接到例如WebLogic服务器时,它允许我根据需要自由连接/断开连接.

任何人都知道这是否正常,或者我是否需要指定一些额外的选项来使调试maven测试更容易?

eclipse debugging maven-2 surefire

26
推荐指数
2
解决办法
2万
查看次数

Maven surefire插件fork模式

默认情况下,maven surefile插件在隔离(分叉)环境中运行测试.您可以使用以下配置覆盖此行为:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <forkMode>never</forkMode>
      </configuration>
    </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

如果需要调试测试,则应使用此配置代码段.或者您可以通过以下方式简单地运行maven:

$ mvn -Dmaven.surefire.debug tests
Run Code Online (Sandbox Code Playgroud)

这将启动端口5005上的调试器.

我的问题是:分支策略有哪些好处?为什么选择maven构建的默认策略?非福祉策略是不是更直接,因此应该用作默认值(maven是约定优于配置工具,对吧)?

maven-2 fork surefire

24
推荐指数
1
解决办法
3万
查看次数

在maven surefire下记录级别

我无法调整java logging的日志记录级别.我正在使用maven surefire(mvn test),并试图从默认的INFO调整为例如FINEST.

我在src/test/resources/logging.properties下有logging.properties文件

在编译之后,我在target/test-classes下看到,我看到一个带有预期配置的logging.properties文件:

java.util.logging.ConsoleHandler.level = FINEST

javax.enterprise.system.container.ejb.level = FINE

...

但是来自glassfish的控制台输出只有INFO/SEVERE级别的消息.

我哪里做错了?或者这是与maven屁股的另一个痛苦?

junit maven-2 surefire

24
推荐指数
2
解决办法
3万
查看次数

在Java 8上设置maven单元测试的时区

如何在Java 8上的maven surefire中设置单元测试的时区?

使用Java 7时,过去常常使用systemPropertyVariables以下配置,但使用Java 8时,测试只使用系统时区.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <systemPropertyVariables>
      <user.timezone>UTC</user.timezone>
    </systemPropertyVariables>
Run Code Online (Sandbox Code Playgroud)

为什么会这样,我该如何解决?

java timezone surefire maven java-8

24
推荐指数
1
解决办法
2万
查看次数

使用Maven Surefire运行依赖jar中包含的JUnit测试

我的maven存储库中有一个包含junit测试的jar,它应该在不同的项目中运行,因为它能够检查项目并测试它的某些功能.不幸的是,正如此功能请求所示,surefire不会接收jar中包含的测试.

在功能请求中,他们建议解压缩jar然后由surefire执行.

我使用maven-dependency-plugin成功解压缩了jar,但无论如何都没有执行包含的测试.这就是我如何配置maven-dependency-plugin以解压我的jar:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>de.mwx.test</groupId>
                        <artifactId>selenium-test-base</artifactId>
                        <version>0.1</version>
                        <overWrite>true</overWrite>
                          <outputDirectory>
                              ${project.build.directory}/classes
                          </outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

任何帮助都会得到满足.

junit jar surefire maven

22
推荐指数
1
解决办法
1万
查看次数

为什么Drools不能使用Java 8?

我刚刚安装了Java 8的最终版本.当我尝试使用Maven构建我的项目时,如果我使用Java 8,许多测试都会失败,但是使用Java 7会很好.我尝试通过命令行运行它,并将JAVA_HOME设置为C:\ Program Files\Java\jdk1.8.0并通过Eclipse选择jdk1.8.0作为已安装JRE中的默认JRE.两者都失败了 请注意,失败的测试都使用Drools 6(及其依赖项).

这是输出:

-------------------------------------------------------------------------------
Test set: com.local.lds.rules.LocmChiTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 1.245 sec <<< FAILURE!
test(com.local.lds.rules.LocmChiTest)  Time elapsed: 0.001 sec  <<< ERROR!
java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
    at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at mockit.internal.util.MethodReflection.invoke(MethodReflection.java:63)
    at mockit.Invocation.proceed(Invocation.java:192)
    at mockit.integration.junit4.internal.BlockJUnit4ClassRunnerDecorator.createTest(BlockJUnit4ClassRunnerDecorator.java:59)
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:95)
    at mockit.internal.mockups.MockMethodBridge.callMock(MockMethodBridge.java:75)
    at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:41)
    at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java)
    at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) …
Run Code Online (Sandbox Code Playgroud)

drools surefire maven java-8

18
推荐指数
1
解决办法
2万
查看次数