Ant, запустите все тесты jUnit
Проблема: тесты (казалось бы, не выполнены)
Шаг 1: Скомпилируйте источник в bin
<target name="compile" depends="init" description="compile the source ">
<javac srcdir="${src}" destdir="${build}" includeantruntime="true" nowarn="yes" debug="true" />
<javac srcdir="${src}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" />
</target>
Шаг 2: Скомпилируйте тесты в bin
<target name="compileTest" depends="compile" description="compile jUnit Test cases ">
<javac srcdir="${test-dir}" destdir="${bin}" includeantruntime="true" nowarn="yes" debug="true" />
</target>
Шаг 3: найдите Test.class и запустите их
<target name="test" depends="compileTest">
<junit>
<formatter type="plain" usefile="false" />
<formatter type="plain" />
<batchtest>
<fileset dir="${bin}" includes="**/Test*.class" />
</batchtest>
</junit>
</target>
Вывод:
Buildfile: /Users/xx/Documents/repositories/app/build.xml
clean:
[delete] Deleting directory /Users/xx/Documents/repositories/app/build
[delete] Deleting directory /Users/xx/Documents/repositories/app/bin
init:
[mkdir] Created dir: /Users/xx/Documents/repositories/app/build
[mkdir] Created dir: /Users/xx/Documents/repositories/app/bin
compile:
[javac] Compiling 145 source files to /Users/xx/Documents/repositories/app/build
[javac] Compiling 145 source files to /Users/xx/Documents/repositories/app/bin
compileTest:
[javac] Compiling 24 source files to /Users/xx/Documents/repositories/app/bin
test:
dist:
[delete] Deleting: /Users/xx/Documents/repositories/app/dist/app.jar
[jar] Building jar: /Users/xx/Documents/repositories/app/dist/app.jar
[copy] Copying 1 file to /Users/xx/Documents/repositories/app/dist
[delete] Deleting: /Users/xx/Documents/repositories/app/dist/app.war
[war] Building war: /Users/xx/Documents/repositories/app/dist/app.war
[copy] Copying 1 file to /Users/xx/Documents/repositories/app/dist
BUILD SUCCESSFUL
Total time: 5 seconds
Что я пропущу, пожалуйста?
Ответы
Ответ 1
Я полагаю, вы можете использовать batchtest
внутри задачи junit
:
<target name="test" depends="compileTest">
<junit>
<classpath>
<pathelement location="bin" />
<pathelement location="lib/junit-4.10.jar"/>
</classpath>
<batchtest>
<fileset dir="${test}">
<include name="**/*Test*" />
</fileset>
</batchtest>
<formatter type="brief" usefile="false"/>
</junit>
</target>
Примечание следующее:
- В
fileset dir="${test}"
должен указываться исходный каталог для тестов.
- В
include name="**/*Test*"
вы не должны указывать расширение .class
; это должно быть .java
или ничего.
- Вам нужно добавить тестовый выходной каталог как "classpath" для элемента задачи
junit
.
У меня был тест с простым проектом и с той же конфигурацией я получил краткий результат. Я использовал Apache Ant 1.7.1.
Ответ 2
Используйте batchtest" следующим образом:
<batchtest>
<fileset dir="${tst-dir}" includes="**/Test*.class" />
</batchtest>
Пример представлен здесь.
EDIT:
Для распечатки резюме см. ant задача junit не сообщает подробности и this
Обратите внимание, что вам больше не нужны атрибуты printsummary="yes"
и showoutput="true"
в задаче junit. Теперь форматировщик заботится о выходе.
<target name="test" depends="compileTest">
<junit>
<formatter type="plain" usefile="false" /> <!-- to screen -->
<formatter type="plain" /> <!-- to file -->
<batchtest>
<fileset dir="${bin}" includes="**/Test*.class" />
</batchtest>
</junit>
</target>