Skip to content

Latest commit

 

History

History
112 lines (87 loc) · 3.67 KB

File metadata and controls

112 lines (87 loc) · 3.67 KB

Studio Lab: Partial Examples

Objective

Use Specmatic Studio to repair incomplete external examples using partial examples, then verify behavior using validation and loop testing.

Time required to complete this lab:

10-15 minutes.

Prerequisites

  • Docker is installed and running.
  • You are in labs/partial-examples.
  • Ports 9000 and 9001 are available for Studio.

Files in this lab

  • .specmatic/repos/labs-contracts/common/openapi/order-bff/product_search_bff_v6.yaml: OpenAPI contract for the BFF API, loaded by specmatic.yaml.
  • examples/*.json: Incomplete external examples that will be fixed using partial examples.
  • specmatic.yaml: Specmatic configuration for contract testing and mocking.
  • docker-compose.yaml: Suite loop setup.

Validate the examples (intentional failure)

docker run --rm \
  -v .:/usr/src/app \
  -v ../license.txt:/specmatic/specmatic-license.txt:ro \
  specmatic/enterprise:latest \
  validate

Windows (PowerShell/CMD) single-line:

docker run --rm -v .:/usr/src/app -v ../license.txt:/specmatic/specmatic-license.txt:ro specmatic/enterprise:latest validate

Output

[OK] Specification product_search_bff_v6.yaml: PASSED
[FAIL] Examples: 0 passed and 3 failed out of 3 total

Start Studio

docker compose --profile studio up studio

Learner task: fix 3 examples using partial examples

In Studio, open product_search_bff_v6.yaml which should be under .specmatic/repos/labs-contracts/common/openapi/order-bff from the left sidebar. You will see that 3 examples have failed validation on the examples tab.

Please do not click the Fix button to make these examples valid. Instead, use partial examples to fix them.

Re-validate after fixing in Studio

docker run --rm \
  -v .:/usr/src/app \
  -v ../license.txt:/specmatic/specmatic-license.txt:ro \
  specmatic/enterprise:latest \
  validate

Windows (PowerShell/CMD) single-line:

docker run --rm -v .:/usr/src/app -v ../license.txt:/specmatic/specmatic-license.txt:ro specmatic/enterprise:latest validate

Output

[OK] Specification simple-openapi-spec.yaml: PASSED
[OK] Examples: 3 passed and 0 failed out of 3 total

Reference

Loop Test

Loop Test in Studio

In Studio, after examples are valid:

  • Go to Mock and click Run (mock server on port 8080).
  • Go to Test, set URL to http://127.0.0.1:8080, then click Run.

Expected: 7 tests passing and 0 failing.

Stop Studio

docker compose --profile studio down -v

Why 7 tests?

You have 3 external examples, plus additional inline examples in the OpenAPI spec.
Specmatic runs tests from both sources, so total generated tests are higher than 3.

Loop Test using CLI

Run the following command to start the mock server and run the tests against it using CLI.

docker compose up --abort-on-container-exit

This runs the suite, starts the dependency mocks, and executes the tests. You should see:

Tests run: 7, Successes: 7, Failures: 0, Errors: 0
docker compose down -v

Pass Criteria

  • Validation shows: 3 passed and 0 failed out of 3 total.
  • Loop test shows: Tests run: 7, Successes: 7, Failures: 0, Errors: 0.

Next step

If you are doing this lab as part of an eLearning course, return to the eLearning site and continue with the next module.