diff --git a/README.md b/README.md index e8b67dd..812c8f2 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ This project contains the system and integration tests of *Test Data Generation for APIs* (TDG). Includes the required test classes, result files and the SUT projects, -along with an additional project (to convert into module) to evaluate the mutation +along with an additional module to evaluate the mutation score of the tests for one of the SUTs. ## Systems Under Test (SUTs) -- Swagger Petstore (`swagger-petstore-main-fork`). +- Swagger Petstore (`sut-petstore` folder). This is a detached fork of https://github.com/swagger-api/swagger-petstore at v1.0.17 (2022-09-30) with some additions -- Market (`swagger-market-fork`). +- Market (`sut-market` folder). This is a detached fork of https://github.com/aleksey-lukyanets/market (2022-02-07) with some additions -- Gestao Hospital (`swagger-gestaoHospital-fork`). +- Gestao Hospital (`sut-gestaoHospital` folder). This is a detached fork of https://github.com/ValchanOficial/GestaoHospital (2023-07-05) with some additions ## Structure of this project @@ -19,20 +19,25 @@ score of the tests for one of the SUTs. - Module `st-tdg-test`: - Java tests (`src/test/java`) for each SUT. - Files for test result comparison (`src/test/resources`) -- A folder for each of the SUTs that are evaluated in this replication package. -- A folder `setup` with scripts to execute each SUT (backend and databases). + - Clasess `*Petstore0*` contain some commented examples to illustrate + some details of the TDG approach. + - There is a common base class for all tests (`BaseAll`) and + Each namespace has an additional base class + with the particular configuration of each SUT. +- A folder for each of the SUTs that are tested in this projects. +- A folder `setup` with scripts to run each SUT (backend and databases). - Module `st-tdg-eval`: To evaluate the effectiveness of the test data my measuring - the mutation score of the tests using PIT (pitest.org). + the mutation score of the tests using PIT (https://pitest.org/). ## How to execute the System Tests -All experiments are enclosed in the Java tests. +The tests are in the `st-tdg-test` module. To run the tests of a SUT in your local development environment: - - Ensure that the port that uses the SUT is not used by other SUT + - Ensure that the port bindings of each SUT are not used by other application - Run the server from the `setup` folder and wait until it is up - - Execute the tests in the namespace that corresponds with the project - - To execute from maven (e.g. for the petstore): `mvn -pl st-tdg-test` + - Execute the tests in the namespace that corresponds with the SUT + - To execute this module from maven: `mvn -pl st-tdg-test test` Port reservation and endpoints: To avoid conflicts when running in local, different host port are reserved for each SUT. @@ -41,7 +46,7 @@ Below are the ports and the main endpoint urls to check that SUTs are working: [api example](http://localhost:8081/api/v3/pet/findByStatus?status=available) | [swagger-ui](http://localhost:8081/) | [api-docs](http://localhost:8081/api/v3/openapi.json) - - Market: 8082 (web), 8083 (api), 8084 (db) + - Market: 8082 (web), 8083 (api), 8087 (db) [api example](http://localhost:8083/products) | [swagger-ui](http://localhost:8083/swagger-ui/index.html) | [api-docs](http://localhost:8083/v2/api-docs) @@ -51,14 +56,16 @@ Below are the ports and the main endpoint urls to check that SUTs are working: The whole sequence of tests for all SUTs is run when executed in CI -## How to evaluate the mutation score +## How to evaluate the Mutation Score -At `st-tdg-eval` run this maven command: +The tests are located in the `st-tdg-eval` module. +Run this maven command: ``` -mvn test-compile org.pitest:pitest-maven:mutationCoverage +mvn -pl st-tdg-eval test-compile org.pitest:pitest-maven:mutationCoverage ``` -Test results are in the `target` folder, and mutation report in `target/pit-reports` +Test results of the module are in the `target` folder, +and the mutation report in `target/pit-reports` ## Graphical TDM models diff --git a/pom.xml b/pom.xml index e45fdef..594e1c3 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ st-tdg-test + st-tdg-eval @@ -89,20 +90,6 @@ 1.8 - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - true - - ${surefireArgLine} - true - - false - ${skipTests} - - org.apache.maven.plugins maven-antrun-plugin diff --git a/st-tdg-eval/.classpath b/st-tdg-eval/.classpath new file mode 100644 index 0000000..1e145ca --- /dev/null +++ b/st-tdg-eval/.classpath @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/st-tdg-eval/.project b/st-tdg-eval/.project new file mode 100644 index 0000000..0de9cf1 --- /dev/null +++ b/st-tdg-eval/.project @@ -0,0 +1,35 @@ + + + st-tdg-eval + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + petstoreMainJava + 2 + PARENT-1-PROJECT_LOC/sut-petstore/src/main/java + + + petstoreMainResources + 2 + PARENT-1-PROJECT_LOC/sut-petstore/src/main/resources + + + diff --git a/st-tdg-eval/.settings/org.eclipse.core.resources.prefs b/st-tdg-eval/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..0180f15 --- /dev/null +++ b/st-tdg-eval/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//TUYA/IN2TEST/github-giis/tdrules-st-tdg/sut-petstore/src/main/java=UTF-8 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/st-tdg-eval/.settings/org.eclipse.jdt.core.prefs b/st-tdg-eval/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/st-tdg-eval/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/st-tdg-eval/pom.xml b/st-tdg-eval/pom.xml index bbeceb8..faa2acf 100644 --- a/st-tdg-eval/pom.xml +++ b/st-tdg-eval/pom.xml @@ -1,77 +1,55 @@ - - - + 4.0.0 - - giis - swagger-petstore-eval - 1.0.0-SNAPSHOT - - - 1.8 - 1.8 - UTF-8 - - 4.3.0 - 1.4.266 - - - - + + io.github.giis-uniovi + tdrules-st-tdg + 1.5.0-SNAPSHOT + + st-tdg-eval + jar + + st-tdg-eval + TDG - Test Data Generation for APIs - Petstore evaluation + http://github.com/giis-uniovi/tdrules-st-tdg + + Software Engineering Research Group (GIIS) - Universidad de Oviedo, ES + http://giis.uniovi.es/ + + io.github.giis-uniovi tdrules-client - ${tdrules.version} - test io.github.giis-uniovi tdrules-client-oa - ${tdrules.version} - test io.github.giis-uniovi tdrules-store-loader - ${tdrules.version} - test giis qagrow - ${qagrow.version} - test org.slf4j slf4j-api - 1.7.36 - ch.qos.logback - logback-classic - 1.2.13 - test + org.apache.logging.log4j + log4j-slf4j2-impl + junit junit - 4.13.2 - test io.github.javiertuya visual-assert - 2.4.1 - test org.projectlombok @@ -81,10 +59,11 @@ + + org.apache.maven.plugins + maven-antrun-plugin + - - - - giis - https://in2test.lsi.uniovi.es/xlib/maven/ - - false - - - true - - - - giis-snapshots - https://in2test.lsi.uniovi.es/xlib/maven-snapshots/ - - true - - - false - - - - - github-giis-uniovi - https://maven.pkg.github.com/giis-uniovi/* - - true - - - false - - - - - + \ No newline at end of file diff --git a/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/Base.java b/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/Base.java index ee49555..27f7b18 100644 --- a/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/Base.java +++ b/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/Base.java @@ -27,7 +27,7 @@ */ @Slf4j public class Base { - protected static final String PETSTORE_SCHEMA_LOCAL = "../swagger-petstore-main-fork/src/main/resources/openapi.yaml"; + protected static final String PETSTORE_SCHEMA_LOCAL = "../sut-petstore/src/main/resources/openapi.yaml"; protected static TdSchema model; // readonly, created before all tests @@ -62,14 +62,12 @@ protected void load(ApiWriter writer, String query) { // Generation and loading: Each test first delete all data previous to the generation and load writer.delete("/test/deleteAll"); - QAGrowApiProcess qagrow = new QAGrowApiProcess(model, new TdRulesApi(), loader); + QAGrowApiProcess qagrow = new QAGrowApiProcess(model, new TdRulesApi().setCache("../.tdrules-cache"), loader); qagrow.genData4ApiQuery(query); } /** - * Instancia un generador de datos configurado con un diccionario para que los - * datos generados no sean solo numeros, sino valores procedentes de un - * diccionario o mascaras + * Dictionary to load more user friendly petstore data, includes values enumertions for strings and masks */ protected IAttrGen getPetstoreDictionary() { return new DictionaryAttrGen() diff --git a/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/TestPetstore.java b/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/TestPetstore.java index a6e3e1d..8c156bd 100644 --- a/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/TestPetstore.java +++ b/st-tdg-eval/src/test/java/test4giis/tdrules/tdg/st/eval/petstore/TestPetstore.java @@ -14,7 +14,7 @@ * (TDG), containing a subset of the main project's tests. To evaluate the * mutation score of the business processes run this command fron maven: * - * mvn test-compile org.pitest:pitest-maven:mutationCoverage + * mvn -pl st-tdg-eval test-compile org.pitest:pitest-maven:mutationCoverage * * As Pitest runs in the same process of the tested methods, the controller is * mocked. Note that petstore does not use Spring, so that MockMvc can be used. @@ -64,7 +64,6 @@ public void testFindOrdersByCategoryAndOrderStatus() { load(mvc, "tds Customer, \"Order\", Pet where Pet.category::name='Dogs' and \"Order\".status='placed'"); testFindOrdersByCategoryAndOrderStatusLoaded = true; } - // Por que si anyado and \"Order\".complete=true, excepcion en qagrow, pero si pongo 1 en vez de true no. ApiResponse pets = mvc.get("/store/findOrdersByCategoryAndOrderStatus?category=Dogs&status=placed"); assertReadResults(pets); } @@ -79,10 +78,6 @@ public void testTotalPetsToDeliverByAddress() { + " group by Customer.address[]::zip"); testTotalPetsToDeliverByAddressLoaded = true; } - // Por que si uso select Customer.address[]::zip, sum(\"Order\".quantity) from - // quantity da varios valores cero, incluso al poner un minimo de uno en el diccionario? - // y si solo pongo tds no? - // por que zip no tiene mascara aplicada? ApiResponse pets = mvc.get("/store/totalPetsToDeliverByAddress"); assertReadResults(pets); }