Skip to content

Commit 5f91702

Browse files
authored
chore: update contributing.md and add new testing_guide.md
1 parent 66cd5b1 commit 5f91702

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ If you’re working locally, it often can be useful to `--amend` a commit, or ut
7979
### Code Reviewing Guide
8080

8181
See the [CODEREVIEWERS file](./CODEREVIEWERS.md).
82+
83+
### Testing & User Stories
84+
85+
All new features and submissions require testing to be written and implemented. See the [Testing Guide file](./TESTING_GUIDE.md).

TESTING_GUIDE.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Testing Guide
2+
3+
Prior to finalizing a submission, tests need to be written to cover new code. What follows is a process outlining test creation.
4+
5+
## User Stories
6+
7+
The first step is to define a user story for the feature in question. We follow a simplified user story model:
8+
9+
Scenario: (FEATURE)
10+
Given (Pre-conditions),
11+
I need to be able to (perform a user action)
12+
in order to (perform an internal action), (optional: specify variables).
13+
14+
Example:
15+
16+
Scenario: Registering an Experiment
17+
Given I am an authorized user,
18+
I need to be able to submit a register request,
19+
in order to register an experiment with a provided name.
20+
21+
Once the user story has been created you can use it as a framework to create your tests.
22+
23+
## Creating the Test
24+
25+
Tests are organized in the [tests](./tests) directory based on their scope (unit, integration, etc.) and what they are testing (restapi, task_engine, etc.).
26+
27+
### Unit Tests
28+
29+
Create a file in the subdirectory of [unit](./tests/unit) which matches your test's conditions with the name "test_(feature).py". This will be the main file where you implement your test.
30+
31+
### Integration Tests
32+
33+
Create a folder in [integration](./tests/integration). This will encapsulate the integration test and will be where the "test_(feature).py" files, conftest.py, and other relevant files are stored.
34+
35+
### Test Files
36+
37+
Test files are organized into 3 main sections: actions, assertions, and tests.
38+
39+
The actions section encompasses functions which directly perform the action they are testing (i.e. the second line in our user story). Using restapi tests as an example, these functions would directly interact with the api by performing a POST, PUT or DELETE.
40+
41+
The assertions section encompasses functions which perform assert statements and check retrieved values against expected ones (this checks the third line in our user story). Again using restapi tests as an example, these functions would perform a GET to retrieve an object and then check it against an expected value within an assert.
42+
43+
The tests section encompasses functions which act as the main test for each feature. They call functions within the actions and assertions sections to fully test the feature. For readability and clarity, include the user story and describe the specific actions being performed within the test in the function docstring. Any feature-specific variables should be defined here. The expected output from the test is defined here and passed to the assertion function.
44+
45+
For a detailed example on how to implement a test file, refer to [test_experiment.py](./tests/unit/restapi/test_experiment.py)
46+
47+
### Conftest.py
48+
49+
PyTest allows for the creation of fixtures to address any pre-conditions or variables that are required for tests to function (i.e. the first line in our user story). They are placed within a [conftest.py](./tests/unit/restapi/conftest.py) file. For unit tests you can add on to the conftest in the relevant subdirectory. Integrations tests will require a new conftest to be defined in their folder. Refer to one of the conftests for help with implementation.
50+
51+
## Running the Test
52+
53+
Tests can be using the following command:
54+
55+
```sh
56+
python -m tox run -e py39-pytest-cov
57+
```
58+
59+
This will give you a code coverage report and run the test to determine if it is successful.

0 commit comments

Comments
 (0)