How to tell Maven2 to execute jUnit tests one by one each in new JVM instance?

前端 未结 3 1658
夕颜
夕颜 2020-12-15 23:13

Is it possible to tell Maven2 to execute every jUnit test in new JVM instance (fork) in serial mode, i.e. one by one.

3条回答
  •  忘掉有多难
    2020-12-16 00:03

    You have to fork the JVM like explained here

    
      org.apache.maven.plugins
      maven-surefire-plugin
      2.9
      
        always
      
    
    

    It should also be possible by just declaring a Sytem property

    mvn -DforkMode=always test
    

    As described in the documentation: "always" forks for each test-class. I do not know if the "pertest" setting will fork for each test.


    Thanks to @Djebel for pointing out that forkMode is deprecated now. There is a detailed documentation on "Fork Options and Parallel Test Execution" and how to use the new parameters forkCount and reuseForks and that also includes the following migration tips:

    Old Setting                         New Setting
    forkMode=once (default)             forkCount=1 (default), reuseForks=true (default)
    forkMode=always                     forkCount=1 (default), reuseForks=false
    forkMode=never                      forkCount=0
    forkMode=perthread, threadCount=N   forkCount=N, (reuseForks=false, if you did not had that one set)
    

提交回复
热议问题