Мы начинаем движение к maven, сначала заверяем наши муравьиные сборки в maven.Запуск муравьиной цели от maven
Мы можем получить maven для создания проекта, но не для запуска тестов. Мы пытаемся выполнить цель тестирования ant, в build.xml, из maven. Конечно, когда мы запускаем тестовую цель из муравья, все в порядке.
Ниже приведена ошибка, отображаемая для одного тестового класса (то же самое для других). У этого класса есть несколько методов тестирования, но никто не запускается. Это похоже на проблему версии 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)
Вот наш ПОМ:
<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>
UPDATE:
Так почему Maven работает с JUnit 3, когда мы сказал ему использовать JUnit 4? Я выполнил тест mvn -X и увидел, что банку JUnit 3.8.1 тянет по какой-то причине, но я не знаю, как понять, почему.
UPDATE:.
Я обнаружил, что Maven плагин antrun зависит от JUnit 3.8.1 http://maven.apache.org/plugins/maven-antrun-plugin/dependencies.html
Так что объясняет, как Junit 3 становится тянут в
Так что мне делать Теперь? Есть ли способ запустить мои тесты JUnit 4 с помощью муравьиной задачи в файле build.xml с помощью плагина maven antrun?
Вы уверены, что зависимость Junit в Maven используется? Возможно, это библиотека Junit, к которой обращается ANT, которая используется. – ziggy
Я посмотрел на него, и плагин maven antrun зависит от junit 3.8.1, поэтому именно поэтому. – atroutt
Я узнал из этого http://stackoverflow.com/questions/2021771/surefire-is-not-picking-up-junit-4-tests, который похож, но там нет решения, кроме, возможно, для удаления плагина, который вызывая конфликт. Я не могу удалить antrun, если нет другого способа запустить муравья из maven. – atroutt