cobertura仪器导致我的一些Junit测试失败

时间:2014-08-18 16:23:27

标签: java linux ant junit cobertura

我在linux OS 2.6.32.45-0.3-xen上有cobertrua 2.0.3和Java 1.6.45#1 SMP 2011-08-22 10:12:58 +0200 x86_64 x86_64 x86_64 GNU / Linux

如果我不通过排除和Junit测试来检测这些类,那么测试工作正常。 只要我的仪器包括那些类,我的Junit测试就会失败。

在我看来,这个乐器并不完整或错误,只有我的一些课程,但不是全部课程。

         ======运行目标仪器====

    <!--
                        Remove the coverage data file and any old instrumentation.
                -->
    <delete file="${basedir}/cobertura.ser" />
    <delete dir="${instrumented.dir}" />

    <!--
                        Instrument the application classes, writing the
                        instrumented classes into ${build.instrumented.dir}.
                -->
    <cobertura-instrument todir="${instrumented.dir}">
        <!--
                                The following line causes instrument to ignore any
                                source line containing a reference to log4j, for the
                                purposes of coverage reporting.
                        -->
        <ignore regex="org.apache.log4j.*" />

        <fileset dir="${classes.dir}">
            <!--
                                        Instrument all the application classes, but
                                        don't instrument the test classes.
                                -->
            <include name="**/*.class" />
            <exclude name="**/*Test*.class" />
            <exclude name="**/*HelloWorld*.class" />
            <exclude name="**/*Mock*.class" />
        </fileset>
    </cobertura-instrument>
</target>

我的HelloWorld.java

    import java.io.IOException;
//import java.util.logging.FileHandler;
//import java.util.logging.Handler;
//import java.util.logging.Level;
import java.util.logging.Logger;


public class HelloWorld {

    private static final Logger LOGGER = Logger.getLogger(HelloWorld.class.getName());

    private String HELLO_WORLD = "Hello World";
    private String HELLO_SWEDEN = "Hello Sweden";
    private String message = "default message";

    public void printHello() throws SecurityException, IOException {
        LOGGER.entering(this.getClass().getName(), "Entering printHello()");
//      Handler fh = new FileHandler("%h/java%u.log");
//      fh.setLevel (Level.FINE);
//      LOGGER.addHandler(fh);
        setMessage(HELLO_WORLD);
        //System.out.println("From printHello():" + getMessage());
        LOGGER.info("message is: " + HELLO_WORLD);
        LOGGER.info("Print message:" + getMessage());

        LOGGER.finest("this is finest");
        LOGGER.finer("this is finer");
        LOGGER.fine("this is fine");
        LOGGER.config("this is config");
        LOGGER.info("this is info");
        LOGGER.warning("this is a warning");
        LOGGER.severe("this is severe");

        Trace.fine(this, "Trace fine print out");
        LOGGER.exiting(this.getClass().getName(), "Exiting printHello()");
    }

    public void printSweden() {

        setMessage(HELLO_SWEDEN);
        System.out.println("From printSweden():" +getMessage());
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

0 个答案:

没有答案