Adatta il fallimento della costruzione con Maven
-
14-11-2019 - |
Domanda
Sto cercando di creare un test di integrazione / accettazione usando in forma. Ecco la struttura della cartella:
-src
--main
---fit
----"html files"
---java
----fit
-----"FIT Fixtures files"
----my
-----package
------"business logic files"
.
Ecco il mio POM.XML (MAVEN2):
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>Test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
...
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>fit-maven-plugin</artifactId>
<version>2.0-beta-3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>fit-maven-plugin</artifactId>
<version>2.0-beta-3</version>
<executions>
<execution>
<configuration>
<sourceDirectory>src/main/fit</sourceDirectory>
<sourceIncludes>*.html</sourceIncludes>
<outputDirectory>${project.basedir}\target</outputDirectory>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
...
</repositories>
</project>
.
Esecuzione del test di adattamento usando mvn integration-test -X
, ottengo un errore causato da:
.java.lang.illegalstateException: l'apparecchio non è riuscito con Conta: 0 Destra, 0 Sbagliato, 0 Ignorato, 4 Eccezioni
Ancora, viene generata l'uscita in forma in
C:\JavaTest\target\customer-bills.html
e contiene un errore che dice:java.lang.RuntimeException: The fixture GivenTheFollowingCustomers was not found.
"GiventeSewingingcustomers" è l'intestazione della tabella nell'HTML:
.<table> <tr> <td colspan="3" class="title">GivenTheFollowingCustomers</td> </tr> ... </table>
Ho pensato che il sistema avrebbe cercato l'apparecchio chiamato
GivenTheFollowingCustomers
? Perché non è in grado di trovarlo?Grazie mille!
Aggiornamento: Il sistema è ora in grado di trovare l'apparecchio per la prima tabella, ma solo il primo! Stavo affrontando il problema perché l'intestazione del tavolo era
GivenTheFollowingCustomers
anzichéfit.GivenTheFollowingCustomers
. Tuttavia, sto ottenendo lo stesso errore per tutte le altre tabelle / infissi in quel file HTML. Ed è bizzarro perché non dipende dalla tabella specifica. Ad esempio, se spostamento della prima tabella (GivenTheFollowingCustomers
) in seconda posizione, smette di funzionare e il primo inizia a funzionare. Qualsiasi indizio ..?Update2: Ho provato a eseguire manualmente i test con la biblioteca Fit (senza Maven) e funziona bene! Inoltre, qualcun altro ha scritto questo: http:// osdir.com/ml/java.maven-plugins.mojo.User/2007-07/msg00000.html e non ha avuto risposte. Possibile bug nel plugin di Fit Maven ..?
Soluzione
It is a known bug with the FIT maven plugin. The fix should have been released in version 2.0-beta-4 but it has never been released. In fact, it seems like development stopped in December 2007 (ouch!). Anyway, it's possible to solve the problem by creating the following class (as seen in the patch):
/**
* Extends ColumnFixture to allow a custom ClassLoader to be used for loading fixtures
*
* @author Mauro Talevi
*/
public class ClassLoaderColumnFixture
extends ColumnFixture
implements FixtureClassLoaderEnabled
{
private FixtureClassLoader classLoader;
public ClassLoaderColumnFixture()
{
this( new FixtureClassLoader() );
}
public ClassLoaderColumnFixture()
{
this( new FixtureClassLoader() );
}
public ClassLoaderColumnFixture( FixtureClassLoader classLoader )
{
this.classLoader = classLoader;
}
public void enableClassLoader( FixtureClassLoader classLoader )
{
this.classLoader = classLoader;
}
public Fixture loadFixture( String fixtureName )
throws InstantiationException, IllegalAccessException
{
return classLoader.newFixture( fixtureName );
}
}
And extending from ClassLoaderColumnFixture
instead of ColumnFixtures
in the fixtures.
This solved my problem, I hope it will be helpful for someone else.
Altri suggerimenti
There is a new maven plugin for fit you can use. Just replace the plugin with:
<plugin>
<groupId>com.github.cradloff</groupId>
<artifactId>fit-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>fixture</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Then there is no need for a special Class Loader Fixture.