簡體   English   中英

Junit測試不會使用ant運行

[英]Junit tests wont run using ant

我已經能夠使用ant成功編譯並運行該項目。 但是,當我嘗試運行測試文件時,它給了我一個奇怪的Reference ./lib/junit-4.11.jar。 我在junit任務中不得不提到的提法中可能做錯了什么。 請指出錯誤。

<target name="clean">
    <delete dir="build"/>
</target>

<target name="compile">
    <mkdir dir="build/classes"/>
    <javac srcdir="./src/com/twu/biblioteca/" destdir="build/classes"/>
</target>

<target name="jar">
    <mkdir dir="build/jar"/>
    <jar destfile="build/jar/Application.jar" basedir="build/classes">
        <manifest>
            <attribute name="Main-Class" value="com.twu.biblioteca.Application"/>
        </manifest>
    </jar>
</target>

<target name="run">
    <java jar="build/jar/Application.jar" fork="true"/>
</target>

<target name="junit" depends="compile">

    <junit printsummary="yes" haltonfailure="no">

        <!-- Project classpath, must include junit.jar -->
        <classpath refid="./lib/junit-4.11.jar" />

        <!-- test class -->
        <classpath location="./test/BooksController" />

        <test name="com.twu.biblioteca.BooksControllerTest"
              haltonfailure="no" todir="./report">
            <formatter type="plain" />
            <formatter type="xml" />
        </test>

    </junit>
</target>

問題出在您的junit classpath元素上。 refid屬性允許您引用預定義的引用,並且ant通知您沒有此類引用。 另外,在junit任務下您應該只具有一個classpath元素(它可以與多個元素一起使用,但是文檔僅支持一個)。

刪除那些classpath元素並替換為

<classpath>
    <pathelement location="lib/junit-4.11.jar"/>
    <pathelement location="test/BooksController"/>
</classpath>

它應該工作。 在這里,我們通過將junit jar添加到路徑,然后添加包含測試的目錄來構建類路徑。 您可能還必須將您的主類添加到該類中 ,並使用另一個路徑指定它們的位置。

有關這些類似路徑的結構的更多信息,請參見ant文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM