pátek 25. srpna 2017
středa 21. června 2017
Jak použít automatické testování REST ve Fitnesse?
Fitnesse - nástroj pro testery, umožňuje psát testy ve formě wiki stránek, spouštět je, generovat reporty a zobrazovat historii provedených testů.
Fitnesse je rozšiřitelný ve formě tzv. fixture. Pro REST rozhraní jsou také možná fixture. Jedním z nich je RestFixture. Náved na přípravu prvního fixture je:
https://stackoverflow.com/questions/35753103/workflow-of-creating-tests-using-restfixture
Fixture je připravený jako Maven archetype. Postup podle návodu zafungoval napoprvé.
Drobné rozdíly:
1)
v dependency jsem použil novější verzi Fitnesse:
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>20161106</version>
</dependency>
2)
pro start jsem musel použít příkaz call start.bat, samotný start.bat mi nezafungoval správně.
Postup - přesně podle https://stackoverflow.com/questions/35753103/workflow-of-creating-tests-using-restfixture :
1) Připravit mvn projekt se základem fixture z již hotového připraveného archetypu.
mvn archetype:generate -DgroupId=com.ibm.cz.fitnesse.rest
.sample -DartifactId=scratch -DarchetypeArtifactId=maven-archetype-quickstart -D
interactiveMode=false
2) Přidat dependency
<dependency>
<groupId>smartrics.restfixture</groupId>
<artifactId>smartrics-RestFixture</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>20161106</version>
</dependency>
a odmazat App.java ze src\main\java\com\ibm\cz\fitnesse\rest\sample
3) Přidat
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
4) Spustit mvn clean package
5) Připravit start.bat s následujícím obsahem:
setLocal EnableDelayedExpansion
set CLASSPATH="
for /R target\dependencies %%a in (*.jar) do (
set CLASSPATH=!CLASSPATH!;%%a
)
set CLASSPATH=!CLASSPATH!"
java -cp !CLASSPATH! fitnesseMain.FitNesseMain -p 9090 -d src\main\resources -e 0
6) Spustit start.bat: call start.bat
POZOR: pouze start.bat na WIN7 nezafunguje správně
7) Vyzkoušet http://localhost:9090
Fitnesse je rozšiřitelný ve formě tzv. fixture. Pro REST rozhraní jsou také možná fixture. Jedním z nich je RestFixture. Náved na přípravu prvního fixture je:
https://stackoverflow.com/questions/35753103/workflow-of-creating-tests-using-restfixture
Fixture je připravený jako Maven archetype. Postup podle návodu zafungoval napoprvé.
Drobné rozdíly:
1)
v dependency jsem použil novější verzi Fitnesse:
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>20161106</version>
</dependency>
2)
pro start jsem musel použít příkaz call start.bat, samotný start.bat mi nezafungoval správně.
Postup - přesně podle https://stackoverflow.com/questions/35753103/workflow-of-creating-tests-using-restfixture :
1) Připravit mvn projekt se základem fixture z již hotového připraveného archetypu.
mvn archetype:generate -DgroupId=com.ibm.cz.fitnesse.rest
.sample -DartifactId=scratch -DarchetypeArtifactId=maven-archetype-quickstart -D
interactiveMode=false
2) Přidat dependency
<dependency>
<groupId>smartrics.restfixture</groupId>
<artifactId>smartrics-RestFixture</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
<version>20161106</version>
</dependency>
a odmazat App.java ze src\main\java\com\ibm\cz\fitnesse\rest\sample
3) Přidat
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
4) Spustit mvn clean package
5) Připravit start.bat s následujícím obsahem:
setLocal EnableDelayedExpansion
set CLASSPATH="
for /R target\dependencies %%a in (*.jar) do (
set CLASSPATH=!CLASSPATH!;%%a
)
set CLASSPATH=!CLASSPATH!"
java -cp !CLASSPATH! fitnesseMain.FitNesseMain -p 9090 -d src\main\resources -e 0
6) Spustit start.bat: call start.bat
POZOR: pouze start.bat na WIN7 nezafunguje správně
7) Vyzkoušet http://localhost:9090
středa 18. ledna 2017
Vyhození fault Java komponenty v Integration Designer
/**
* Method generated to support implementation of operation "operation1" defined for WSDL port type
* named "SimpleIntf".
*
* The presence of commonj.sdo.DataObject as the return type and/or as a parameter
* type conveys that it is a complex type. Please refer to the WSDL Definition for more information
* on the type of input, output and fault(s).
*/
public DataObject operation1(DataObject input1) throws Throwable{
Service service = locateService_SimpleIntfPartner();
try {
service.invoke("operation1", input1);
} catch (Throwable t) {
System.out.println("Nastala chyba");
com.ibm.websphere.bo.BOFactory boFactory = (com.ibm.websphere.bo.BOFactory) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOFactory");
DataObject fault = boFactory.create("http://JMSDemoModule", "ServiceFault");
fault.setString("error", t.getMessage());
throw new ServiceBusinessException(fault);
}
return input1;
}
Přihlásit se k odběru:
Příspěvky (Atom)