Trying to get ScalaTest working: “There are no tests to run” when doing “mvn test”

后端 未结 3 817
感情败类
感情败类 2020-12-29 12:13

Edit: I finally got it to work!!!

It needed a combination of JUnit in the pom.xml, and three statements in my .scala:

import org.junit.runner.RunWith         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 12:41

    You might want to use the scalatest-maven-plugin to run your scala tests.

    Also make sure that you use the test for jars needed only for test purposes.

    This is how I have defined my pom.xml for using ScalaTest:

    
    
    
        4.0.0
    
        com.stackoverflow
        Q13036561
        1.0-SNAPSHOT
    
        ${project.artifactId}-${project.version}
    
        
            UTF-8
            2.9.2
            2.0.M4
        
    
        
            
                org.scala-lang
                scala-library
                ${scala.version}
            
            
                org.scalatest
                scalatest_${scala.version}
                ${scalatest.version}
                test
            
        
    
        
            
                
                    org.scala-tools
                    maven-scala-plugin
                    2.15.2
                    
                        
                            scala-compile
                            
                                compile
                                testCompile
                            
                            
                                
                                    -make:transitive
                                    -dependencyfile
                                    ${project.build.directory}/.scala_dependencies
                                
                            
                        
                    
                
                
                
                    org.scalatest
                    scalatest-maven-plugin
                    1.0-M2
                    
                        ${project.build.directory}/surefire-reports
                        W 
                    
                    
                        
                            scala-test
                            
                                test
                            
                        
                    
                
            
        
    
    

    As you can see I have also added a section that disables the surefire plugin if you really don't want to run it. It is commented in the above pom but if you want to disable the surefire plugin just uncomment that part.

    I am using IntelliJ too and there are no problems at all with this combination. Just run the tests from within IntelliJ or by using mvn test, they will both work.

提交回复
热议问题