Skip to content

Commit

Permalink
Add docker alternatives to java -jar commands in contract_tests page
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshnikam671 committed Sep 4, 2024
1 parent 9b868f3 commit 3522805
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions documentation/contract_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ Here is a sample application that is is implementing this specification. You can

Let us now run the ```employees.yaml``` as a test against the above sample application.

```{{ site.spec_cmd }} test employees.yaml --testBaseURL https://my-json-server.typicode.com```
```bash
{{ site.spec_cmd }} test employees.yaml --testBaseURL https://my-json-server.typicode.com
```

Alternatively, you can use Docker:

```bash
docker run znsio/specmatic test employees.yaml --testBaseURL https://my-json-server.typicode.com
```

The results should end with below text.

Expand Down Expand Up @@ -221,7 +229,17 @@ The [`employees.yaml`](https://github.com/znsio/externalised-example-jsons-sampl

Let us now run `employees.yaml` as a test against the sample application.

```{{ site.spec_cmd }} test --testBaseURL https://my-json-server.typicode.com employees.yaml```
Here’s how you can present that command with `site.spec_cmd` and the Docker alternative in Bash format:

```bash
{{ site.spec_cmd }} test --testBaseURL https://my-json-server.typicode.com employees.yaml
```

Alternatively, you can use Docker:

```bash
docker run znsio/specmatic test --testBaseURL https://my-json-server.typicode.com employees.yaml
```

Note: Since the folder is named `employees_examples` and colocated with the spec file `employees.yaml`, by convention it is automatically picked up. However if your folder has different name and / or located in another path, you can explicitly pass that folder as a parameter using the `--examples` CLI Argument (Please run `specmatic test --help` to learn more).

Expand All @@ -239,6 +257,12 @@ Instead of creating the above example JSONs by hand, you can also generate the e
java -jar specmatic.jar examples employees.yaml
```

Alternatively, you can use Docker:

```bash
docker run znsio/specmatic examples employees.yaml
```

In the above case, example JSON files will be written into the directory named `employees_examples`. You can then update the files to suit your needs and use them.

### Boundary Condition Testing
Expand All @@ -249,7 +273,15 @@ Specmatic can help you verify / assess such boundary condition behavior and the

```export SPECMATIC_GENERATIVE_TESTS=true```

```{{ site.spec_cmd }} test --testBaseURL https://my-json-server.typicode.com employees.yaml```
```bash
{{ site.spec_cmd }} test --testBaseURL https://my-json-server.typicode.com employees.yaml
```

Alternatively, you can use Docker:

```bash
docker run znsio/specmatic test --testBaseURL https://my-json-server.typicode.com employees.yaml
```

Earlier for the same input we saw 4 tests and all of which were successful. This time around you will see a total of 26 tests, of which 21 are failires

Expand All @@ -263,7 +295,15 @@ Demo: [Video](https://youtu.be/U5Agz-mvYIU?t=216)

You can get the JUnit output from the Specmatic command using an extra parameter.

`{{ site.spec_cmd }} --testBaseURL https://my-json-server.typicode.com --junitReportDir ./test-output`
```bash
{{ site.spec_cmd }} --testBaseURL https://my-json-server.typicode.com --junitReportDir ./test-output
```

Alternatively, you can use Docker:

```bash
docker run znsio/specmatic --testBaseURL https://my-json-server.typicode.com --junitReportDir ./test-output
```

The command will create JUnit test xml output in the specified directory which you can then include as part of CI pipeline results etc.

Expand Down Expand Up @@ -324,7 +364,18 @@ Specmatic will use the git command to checkout the git repository provided in th

On the command line, `cd` into the directory containing the Specmatic configuration file.

Run this command: `{{ site.spec_cmd }} --testBaseURL https://my-json-server.typicode.com`
Run this command:

```bash
{{ site.spec_cmd }} --testBaseURL https://my-json-server.typicode.com
```

Alternatively, you can use Docker:

```bash
docker run znsio/specmatic --testBaseURL https://my-json-server.typicode.com
```
```

Note that no contracts are passed to Specmatic. Since no contracts have been passed, Specmatic looks for the Specmatic configuration file in the current working directory, checks out the contract repo, and runs the specified contracts as contract tests.

Expand Down

0 comments on commit 3522805

Please sign in to comment.