How to use the command `cotton` (with examples)
cotton
is a Markdown test specification runner. It allows you to run tests written in Markdown format and provides various options for customization. This article will cover three use cases of the cotton
command along with their code, motivations, explanations, and example outputs.
Use case 1: Use a specific base URL
Code:
cotton -u base_url path/to/file.md
Motivation:
- Running tests with a specific base URL is useful when you want to test web services or APIs that require a specific URL.
- This use case allows you to easily switch between different environments (e.g., development, staging, production) without modifying the test files.
Explanation:
-u base_url
: Specifies the base URL to be used for running the tests.path/to/file.md
: Specifies the path to the Markdown file containing the test specifications.
Example output:
Running tests from 'path/to/file.md' against 'base_url'...
Test 1: Passed
Test 2: Passed
Test 3: Failed
Use case 2: Disable certificate verification (insecure mode)
Code:
cotton -u base_url -i path/to/file.md
Motivation:
- Disabling certificate verification is helpful when you are testing an application that uses self-signed or invalid SSL certificates, or when running tests locally with a self-signed certificate.
- This option allows you to bypass certificate errors that could otherwise interrupt the test execution.
Explanation:
-u base_url
: Specifies the base URL to be used for running the tests.-i
: Enables insecure mode, disabling certificate verification.
Example output:
Running tests from 'path/to/file.md' against 'base_url' in insecure mode...
Test 1: Passed
Test 2: Passed
Test 3: Failed
Use case 3: Stop running when a test fails
Code:
cotton -u base_url -s path/to/file.md
Motivation:
- Stopping the execution when a test fails can be helpful during development or debugging, as it allows you to immediately identify the cause of failure without unnecessary processing.
- It saves time and resources by avoiding the execution of subsequent tests once one test has already failed.
Explanation:
-u base_url
: Specifies the base URL to be used for running the tests.-s
: Stops the execution as soon as a test fails.
Example output:
Running tests from 'path/to/file.md' against 'base_url'...
Test 1: Passed
Test 2: Failed
Conclusion:
The cotton
command is a powerful and convenient tool for running Markdown test specifications. With the ability to use a specific base URL, enable insecure mode, and stop running when a test fails, it provides flexibility and control over the testing process. By following the examples provided in this article, you can effectively utilize the cotton
command to streamline your testing workflow.