{"id":44402830,"url":"https://github.com/redhat-appdev-practice/schemathesis-lab","last_synced_at":"2026-02-12T06:29:19.599Z","repository":{"id":52412069,"uuid":"267394842","full_name":"redhat-appdev-practice/schemathesis-lab","owner":"redhat-appdev-practice","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-26T16:20:17.000Z","size":32,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-28T09:59:01.177Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redhat-appdev-practice.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-27T18:21:20.000Z","updated_at":"2023-06-04T21:01:29.000Z","dependencies_parsed_at":"2022-09-08T16:01:21.729Z","dependency_job_id":null,"html_url":"https://github.com/redhat-appdev-practice/schemathesis-lab","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/redhat-appdev-practice/schemathesis-lab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redhat-appdev-practice%2Fschemathesis-lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redhat-appdev-practice%2Fschemathesis-lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redhat-appdev-practice%2Fschemathesis-lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redhat-appdev-practice%2Fschemathesis-lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redhat-appdev-practice","download_url":"https://codeload.github.com/redhat-appdev-practice/schemathesis-lab/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redhat-appdev-practice%2Fschemathesis-lab/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29360644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T01:03:07.613Z","status":"online","status_checked_at":"2026-02-12T02:00:06.911Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-12T06:29:19.434Z","updated_at":"2026-02-12T06:29:19.588Z","avatar_url":"https://github.com/redhat-appdev-practice.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenApi Testing with Schemathesis\n\n\n## Intro\nIn this lab we are going to look at testing our application using test cases that are generated using the\nOAS(OpenAPI Spec). To accomplish this task we will be using a tool called Schemathesis.\n\nSchemathesis is a tool for testing your web applications built with an Open API specifications.\nIt reads the application schema and generates test cases which will ensure that your application is compliant with its\n schema.\nThe nice thing about Schemathesis is that The application being test could be written in any language, the only thing\nyou need is a valid API schema in a supported format. For more information on Schemathesis, you can check out the\nproject page [here](https://github.com/kiwicom/schemathesis).\n\n## Setup\n### Project Base\nWe'll be using the Todo project that we created at the beginning of the series to test with. If you need a new copy\nof the project follow these steps:\n1. Clone the project: `https://github.com/redhat-appdev-practice/schemathesis-lab.git`\n2. Generate the sources and make sure that the application runs without issue: `mvn spring-boot:run`\n\n### Install Schemathesis\n1. The first thing we're going to do is set up a virtual environment for our python packages:\n`pip install --user virtualenv`\n2. Create a new virtual environment in your project folder: `python -m venv myvenv`\n3. Activate your new virtual environment: `source myvenv/bin/activate`\n   - `source myvenv/Scripts/activate` for Windows\n4. Install Schemathesis: `pip install schemathesis`\n\n## Run the tests\n1. Ensure that the application is running (the tests will be run against the running application): `mvn spring-boot:run`\n2. In our project we are using an OAS that is in a remote repo, Scemathesis allows you to run tests against both local\nremote schemas.\n    - For local: `schemathesis run todo.yaml --base-url http://localhost:8080`\n    - For remote: `schemathesis run https://raw.githubusercontent.com/redhat-appdev-practice/schemathesis-lab/master/todo.yaml --base-url http://localhost:8080`\n\n        \u003csub\u003eNote: there should be failures for both of these runs\u003c/sub\u003e\n\n## Fix the tests\n1. In order to fix the failing tests we need to stub out each of the endpoints that are declared in our OAS\n2. Add the following to the TodosApiController:\n    ```java\n\n    @Override\n    public ResponseEntity\u003cVoid\u003e createTodo( Todo todo, Boolean completed) {\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(200);\n\n    }\n\n    @Override\n    public ResponseEntity\u003cVoid\u003e deleteTodo(String todoId) {\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(200);\n\n    }\n\n    @Override\n    public ResponseEntity\u003cList\u003cTodo\u003e\u003e getTodos( Boolean completed) {\n\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(200);\n\n    }\n\n    @Override\n    public ResponseEntity\u003cVoid\u003e updateTodo(String todoId, Todo todo) {\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(200);\n\n    }\n    ```\n3. Rerun the tests: `schemathesis run todo.yaml --base-url http://localhost:8080`\n4. By default Schemathesis only tests that the response code is less than 500, but there are more options for test cases.  \n   Run `schemthesis run --help` to see more testing options, specifically the --checks option.\n5. Rerun the tests using all available checks: `schemathesis run todo.yaml --checks all --base-url http://localhost:8080`\n6. Update the TodosApiController methods to conform to the OAS:\n   ```java\n   \n    @Override\n    public ResponseEntity\u003cVoid\u003e createTodo(@Valid Todo todo, @Valid Boolean completed) {\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(201));\n    }\n\n    @Override\n    public ResponseEntity\u003cVoid\u003e deleteTodo(String todoId) {\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(204));\n    }\n\n    @Override\n    public ResponseEntity\u003cList\u003cTodo\u003e\u003e getTodos(@Valid Boolean completed) {\n        return ResponseEntity.status(200).body(new ArrayList\u003cTodo\u003e() );\n    }\n\n    @Override\n    public ResponseEntity\u003cVoid\u003e updateTodo(String todoId, Todo todo) {\n        return new ResponseEntity\u003c\u003e(HttpStatus.valueOf(202));\n    }\n    ```\n7. Run the tests one final time: `schemathesis run todo.yaml --checks all --base-url http://localhost:8080`\n\n## Extra Testing\n1. Schemathesis offers added functionality if you want to test a specific part of your application.\n2. Create python file test.py:\n    ```python\n    # test.py\n    import schemathesis\n\n    schema = schemathesis.from_path('./todo.yaml')\n    schema.base_url = 'http://localhost:8080'\n\n    @schema.parametrize()\n    def test_time(case):\n        response = case.call()\n        assert response.elapsed.total_seconds() \u003c 1\n    ```\n 3. This is an example to check that all endpoints execute in under a second\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredhat-appdev-practice%2Fschemathesis-lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredhat-appdev-practice%2Fschemathesis-lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredhat-appdev-practice%2Fschemathesis-lab/lists"}