-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Integration Tests
To run integration test for an API client or server stub, go to the sample directory which contains pom.xml
and then run mvn integration-test
.
To identify API client or server stub tests with pom.xml, run find samples -name "pom.xml"
under Mac/Linux.
CI | Config |
---|---|
Travis | .travis.yml |
AppVeyor | appveyor.yml |
CircleCI | circle.yml |
bitrise.io | bitrise.yml |
Github Actions | workflows |
1. Create pom.xml in the sample directory
Let's say the new sample folder is openapi-generator/samples/client/petstore/ruby/
. We will need to create pom.xml used by Maven to execute commands for testing the Ruby Petstore client.
- artifactId must be unique
- use exec-maven-plugin to execute commmands (bundle install --path vendor/bundle, bundle exec rspec)
To test it locally, please run mvn integration-test
2. Update root-level pom.xml to include the new directory
Please update pom.xml.
For example, search for "ruby" in pom.xml to see how the Ruby petstore folder is added.
3. Run the test server locally
To setup the test server locally, please run
docker pull swaggerapi/petstore
docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore
and add the following entry to your host table:
127.0.0.1 petstore.swagger.io
Echo server tests are newly added in Nov 2022. Eventually it will replace the PetStore server tests, which couldn't meet the growing requirements in terms of test coverage of the auto-generated code.
To run the server:
git clone https://github.com/wing328/http-echo-server -b openapi-generator-test-server
cd http-echo-server
npm install
npm start
Echo server OpenAPI spec:
modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
Example of a sample config:
generatorName: java
outputDir: samples/client/echo_api/java/native
library: native
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: echo-api-native
hideGenerationTimestamp: "true"
To facilitate testing, usually we create a helper to parse the response from the echo server, e.g. https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/echo_api/java/native/src/test/java/org/openapitools/client/EchoServerResponseParser.java
Here is an example PR to add tests for Java (okhttp-gson) client: https://github.com/OpenAPITools/openapi-generator/pull/14442