Running “pure” JUnit 4 tests using ant

后端 未结 9 705
一个人的身影
一个人的身影 2020-12-25 13:05

We have migrated to both JUnit 4 and ant 1.7

The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant.

According to t

9条回答
  •  隐瞒了意图╮
    2020-12-25 13:24

    Ant ships with a version of JUnit 3 by default. JUnit 3 has no support for test annotations.

    To use the JUnit 4 annotations from the junit task make sure that you provide the location of a JUnit 4 jar in a nested classpath element of the junit task (see this entry in the ant FAQ).

    
        
            
            
        
    
        
    
        
            
        
    
    

    This is a preferable solution to overwriting the ant-junit.jar in ANT_HOME/lib as it means you can keep your JUnit jar in source control alongside your code making upgrades to later versions straightforward.

    Note that whilst I haven't specified any include pattern in my fileset above this does mean that the junit task will attempt to run JUnit against all the classes in that directory structure which might result in a number of classes being included that don't contain any tests depending on how you have structured your source files.

提交回复
热议问题