forked from Kiki-Jiji/QA_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-Testing_FrameWorks.Rmd
38 lines (23 loc) · 2.19 KB
/
05-Testing_FrameWorks.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Testing Frameworks
## What exactly is a test
Testing is just checking that the expected result is the same as the actual result. Automated testing is moving from doing this in a informal ad-hoc way to an automated process which is repeatable.
Tests should be
* Fast
* Independent
* Repeatable (deterministic)
* Self-validating (no manual steps)
* Thorough (How much do you trust they cover everything?)
There are common testing frameworks which make testing much simpler.
* For R [Testthat](http://r-pkgs.had.co.nz/tests.html)
* For python [pytest](https://docs.pytest.org/en/latest/)
### Unit Test
Unit testing is the cornerstone of modern software development. The purpose is to validate that each unit of the software performs as designed. A unit is the smallest testable part, such as a function. A unit test might check that for a given input you get a certain output. This gives assurance that for the tested cases your function will preform as expected. This might be checking that your code preforms as expected when given a missing value, or a negative value.
If all tests are passing then all of the cases that are tested for will work. This removes a lot of the burden of review.
Unit testing increases confidence in maintaining or changing code. This is because a test which catch if a change has introduced an error quickly. This also encourages good practice as to make unit testing possible code will need to be modular making it easier to reuse.
### Integration Tests
Unit tests ensure that the units of code works as expected, integration tests ensure that the units work together. An example is testing to ensure that a series of functions together do what is expected. In R and Python this can be achieved using the same framework as unit tests.
There is a question about how much of your code should you test. This depends on the complexity of system and the importance. For statistics QAAD can be used as framework to gauge the appropriate level of testing. For modeling the AQUA book gives a framework for the appropriate level of QA.
### Test Driven Development
## References
* [Testing Blog](http://www.tdda.info/test-driven-development-a-review)
* [Testthat](http://r-pkgs.had.co.nz/tests.html)