Difference between revisions of "RPR-Unit testing"
Jump to navigation
Jump to search
Time management: Before you begin, estimate how long it will take you to complete this unit. Then, record in your course journal: the number of hours you estimated, the number of hours you worked on the unit, and the amount of time that passed between start and completion of this unit.
Journal: Document your progress in your Course Journal. Some tasks may ask you to include specific items in your journal. Don't overlook these.
Insights: If you find something particularly noteworthy about this unit, make a note in your insights! page.
m |
m |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <div id=" | + | <div id="ABC"> |
− | + | <div style="padding:5px; border:1px solid #000000; background-color:#b3dbce; font-size:300%; font-weight:400; color: #000000; width:100%;"> | |
Testing R code | Testing R code | ||
− | + | <div style="padding:5px; margin-top:20px; margin-bottom:10px; background-color:#b3dbce; font-size:30%; font-weight:200; color: #000000; "> | |
− | + | (Code testing in R with the testthat package) | |
− | + | </div> | |
− | |||
− | |||
− | |||
− | Code testing in R with the testthat package | ||
</div> | </div> | ||
− | {{ | + | {{Smallvspace}} |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <div style="padding:5px; border:1px solid #000000; background-color:#b3dbce33; font-size:85%;"> | |
− | + | <div style="font-size:118%;"> | |
− | + | <b>Abstract:</b><br /> | |
− | < | ||
− | <div | ||
− | |||
<section begin=abstract /> | <section begin=abstract /> | ||
− | |||
This unit discusses how to put tests in R into practice with the testthat package. | This unit discusses how to put tests in R into practice with the testthat package. | ||
<section end=abstract /> | <section end=abstract /> | ||
− | + | </div> | |
− | + | <!-- ============================ --> | |
− | + | <hr> | |
− | + | <table> | |
− | == | + | <tr> |
− | === | + | <td style="padding:10px;"> |
− | < | + | <b>Objectives:</b><br /> |
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | < | ||
This unit will ... | This unit will ... | ||
* ... introduce the testthat package; | * ... introduce the testthat package; | ||
* ... teach how to write tests; | * ... teach how to write tests; | ||
* ... demonstrate best practice to organize your tests. | * ... demonstrate best practice to organize your tests. | ||
− | + | </td> | |
− | + | <td style="padding:10px;"> | |
− | + | <b>Outcomes:</b><br /> | |
− | |||
− | |||
− | < | ||
After working through this unit you ... | After working through this unit you ... | ||
* ... can write your own tests; | * ... can write your own tests; | ||
* ... can organize your tests in files and a testing directory to simplify running them. | * ... can organize your tests in files and a testing directory to simplify running them. | ||
+ | </td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | <!-- ============================ --> | ||
+ | <hr> | ||
+ | <b>Deliverables:</b><br /> | ||
+ | <section begin=deliverables /> | ||
+ | <li><b>Time management</b>: Before you begin, estimate how long it will take you to complete this unit. Then, record in your course journal: the number of hours you estimated, the number of hours you worked on the unit, and the amount of time that passed between start and completion of this unit.</li> | ||
+ | <li><b>Journal</b>: Document your progress in your [[FND-Journal|Course Journal]]. Some tasks may ask you to include specific items in your journal. Don't overlook these.</li> | ||
+ | <li><b>Insights</b>: If you find something particularly noteworthy about this unit, make a note in your [[ABC-Insights|'''insights!''' page]].</li> | ||
+ | <section end=deliverables /> | ||
+ | <!-- ============================ --> | ||
+ | <hr> | ||
+ | <section begin=prerequisites /> | ||
+ | <b>Prerequisites:</b><br /> | ||
+ | This unit builds on material covered in the following prerequisite units:<br /> | ||
+ | *[[FND-CSC-Test_driven_development|FND-CSC-Test_driven_development (Test Driven Development)]] | ||
+ | <section end=prerequisites /> | ||
+ | <!-- ============================ --> | ||
+ | </div> | ||
− | {{ | + | {{Smallvspace}} |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | {{ | + | {{Smallvspace}} |
− | + | __TOC__ | |
− | |||
− | |||
− | |||
− | |||
{{Vspace}} | {{Vspace}} | ||
− | </ | + | === Evaluation === |
− | <div | + | <b>Evaluation: NA</b><br /> |
+ | <div style="margin-left: 2rem;">This unit is not evaluated for course marks.</div> | ||
== Contents == | == Contents == | ||
− | |||
{{ABC-unit|RPR-Unit_testing.R}} | {{ABC-unit|RPR-Unit_testing.R}} | ||
− | |||
− | |||
− | |||
− | |||
== Further reading, links and resources == | == Further reading, links and resources == | ||
Line 100: | Line 77: | ||
<!-- {{WWW|WWW_GMOD}} --> | <!-- {{WWW|WWW_GMOD}} --> | ||
<div class="reference-box">[https://cran.r-project.org/web/packages/testthat/testthat.pdf testthat package reference pdf] (on CRAN)</div> | <div class="reference-box">[https://cran.r-project.org/web/packages/testthat/testthat.pdf testthat package reference pdf] (on CRAN)</div> | ||
− | + | * [https://blog.kentcdodds.com/write-tests-not-too-many-mostly-integration-5e8c7fff591c Kent C. Dodds on unit testing vs. integration testing (blog post)] | |
− | |||
− | |||
== Notes == | == Notes == | ||
− | |||
− | |||
<references /> | <references /> | ||
{{Vspace}} | {{Vspace}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<div class="about"> | <div class="about"> | ||
Line 160: | Line 93: | ||
:2017-08-05 | :2017-08-05 | ||
<b>Modified:</b><br /> | <b>Modified:</b><br /> | ||
− | : | + | :2020-09-24 |
<b>Version:</b><br /> | <b>Version:</b><br /> | ||
− | :1. | + | :1.1 |
<b>Version history:</b><br /> | <b>Version history:</b><br /> | ||
+ | *1.1 2020 Maintenance | ||
*1.0 New contents | *1.0 New contents | ||
*0.1 First stub | *0.1 First stub | ||
</div> | </div> | ||
− | |||
− | |||
{{CC-BY}} | {{CC-BY}} | ||
+ | [[Category:ABC-units]] | ||
+ | {{UNIT}} | ||
+ | {{LIVE}} | ||
</div> | </div> | ||
<!-- [END] --> | <!-- [END] --> |
Latest revision as of 14:26, 24 September 2020
Testing R code
(Code testing in R with the testthat package)
Abstract:
This unit discusses how to put tests in R into practice with the testthat package.
Objectives:
|
Outcomes:
|
Deliverables:
Prerequisites:
This unit builds on material covered in the following prerequisite units:
Evaluation
Evaluation: NA
This unit is not evaluated for course marks.
Contents
Task:
- Open RStudio and load the
ABC-units
R project. If you have loaded it before, choose File → Recent projects → ABC-Units. If you have not loaded it before, follow the instructions in the RPR-Introduction unit. - Choose Tools → Version Control → Pull Branches to fetch the most recent version of the project from its GitHub repository with all changes and bug fixes included.
- Type
init()
if requested. - Open the file
RPR-Unit_testing.R
and follow the instructions.
Note: take care that you understand all of the code in the script. Evaluation in this course is cumulative and you may be asked to explain any part of code.
Further reading, links and resources
testthat package reference pdf (on CRAN)
Notes
About ...
Author:
- Boris Steipe <boris.steipe@utoronto.ca>
Created:
- 2017-08-05
Modified:
- 2020-09-24
Version:
- 1.1
Version history:
- 1.1 2020 Maintenance
- 1.0 New contents
- 0.1 First stub
This copyrighted material is licensed under a Creative Commons Attribution 4.0 International License. Follow the link to learn more.