Add tests: how? #99
DominiqueMakowski
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a good first issue for new contributors, as it takes little time, doesn't require advanced programming skills and is a good occasion to discover functions and how they work.
By clicking on the "coverage" badge under the logo on the README page, then on the "neurokit2" folder button at the bottom, you can see the breakdown of testing coverage for each function:
https://codecov.io/gh/neuropsychology/NeuroKit/tree/master/neurokit2
This percentage of coverage needs be improved☺️ The common approach is to identify functions, methods or arguments that are not tested, and then try to write a small test to cover them (i.e., a small self-contained piece of code that will run through a given portion of code and which output is tested (e.g.,
assert x == 3
) and depends on the correct functioning of that code), and then add this test to the appropriate testing file.For instance, let's imagine the following function:
In order to test that function, I have to write some code that "runs through" it and put in a function which name starts with
test_*
, for instance:This will go through the function, which default method is
"great"
, therefore adds3
to the input (here 1), and so the result should be 4. And the test makes sure that it is 4. However, we also need to add a second test to cover the other method of the function (whenmethod != "great"
), for instance:I could have written
assert output == 5
, however, I decided instead to check the type of the output (whether it is an integer). That's the thing with testing, it requires to be creative, but also in more complex cases, to be clever about what and how to test. But it's an interesting challenge 😏You can see examples of tests in the existing test files.
Do not hesitate to ask for more info!
Beta Was this translation helpful? Give feedback.
All reactions