Мы начинаем переход к maven, сначала оборачивая наши сборки муравьев в maven.
Мы можем заставить maven создать проект, но не запускать тесты.Мы пытаемся выполнить цель теста ant в build.xml из maven.Конечно, когда мы запускаем тестовую цель из ant, все в порядке.
Ниже приведена ошибка, которая отображается для одного тестового класса (то же самое для других).В этом классе есть несколько методов тестирования, но ни один из них не запускается.Кажется, это проблема версии JUnit;тесты - это тесты JUnit 4, и если мы изменим класс теста для расширения TestCase (стиль JUnit 3), он найдет тесты.
No tests found in org.mathforum.common.dao.ExampleBaseObjectDaoTest
junit.framework.AssertionFailedError: No tests found in org.mathforum.common.dao.ExampleBaseObjectDaoTest at
org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:327) at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) at
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) at
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at
org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at
org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at
org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at
org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at
org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at
org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Вот наш pom:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>mf-common</artifactId>
<groupId>org.mathforum</groupId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId> <!-- apectj ant plugin -->
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.5</version>
<!--scope>test</scope -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<!--scope>test</scope -->
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml">
<target name="build" />
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml">
<target name="test" />
<!-- need test failure to fail the build -->
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.5</version>
<!--scope>test</scope -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<!--scope>test</scope -->
</dependency>
</dependencies>
</project>
А вот мой build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="mf-common" xmlns:aspectj="antlib:org.aspectj">
<path id="EAR Libraries.libraryclasspath" />
<path id="aspectj.libraryclasspath">
<fileset dir="lib">
<include name="*.jar" />
</fileset>
</path>
<path id="common.classpath">
<fileset dir="test/lib">
<include name="*.jar" />
</fileset>
<path refid="aspectj.libraryclasspath" />
<path refid="EAR Libraries.libraryclasspath" />
</path>
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
<classpath>
<path refid="common.classpath" />
<pathelement location="lib/aspectjtools.jar" />
</classpath>
</taskdef>
<property environment="env" />
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.6" />
<property name="source" value="1.6" />
<target name="init">
<mkdir dir="bin" />
<copy includeemptydirs="false" todir="bin">
<fileset dir="src" excludes="**/*.launch, **/*.java" />
</copy>
<copy includeemptydirs="false" todir="bin">
<fileset dir="test/src" excludes="**/*.launch, **/*.java" />
</copy>
</target>
<target name="clean">
<delete dir="bin" />
<delete file="dist/${ant.project.name}.jar" />
</target>
<target depends="clean" name="cleanall" />
<target depends="init" name="build">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src" />
<classpath refid="common.classpath" />
</javac>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="test/src" />
<classpath refid="common.classpath" />
</javac>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src" excludes="**/*.launch, **/*.java" />
</copy>
<copy includeemptydirs="false" todir="bin">
<fileset dir="test/src" excludes="**/*.launch, **/*.java" />
</copy>
<echo message="after javac" />
<aspectj:iajc debug="true" noweave="true" outJar="dist/mf-common.jar" sourceRootCopyFilter="**/CVS/*,**/*.java,**/*properties" sourceroots="bin/" source="${source}" target="${target}">
<classpath refid="common.classpath" />
</aspectj:iajc>
</target>
<target name="test" depends="build">
<ant dir="${basedir}" inheritAll="false" antfile="test.xml" />
</target>
</project>
ОБНОВЛЕНИЕ:
Так почему же maven работает с JUnit 3, когда мы сказали ему использовать JUnit 4?Я запустил тест mvn -X и увидел, что банка JUnit 3.8.1 почему-то вытягивается, но я не знаю, как выяснить, почему.
ОБНОВЛЕНИЕ:
Я обнаружил, что плагин maven antrun зависит от junit 3.8.1 http://maven.apache.org/plugins/maven-antrun-plugin/dependencies.html
Это объясняет, как Junit 3 получаетподъехал.
Так что мне теперь делать?Есть ли способ запустить мои тесты JUnit 4 с помощью задачи ant в build.xml с помощью плагина maven antrun?