Difference between revisions of "RPR-Unit testing"

From "A B C"
Jump to navigation Jump to search
m
m
Line 1: Line 1:
<div id="BIO">
+
<div id="ABC">
  <div class="b1">
+
<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>
+
<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)
  {{Vspace}}
+
</div>
 
 
<div class="keywords">
 
<b>Keywords:</b>&nbsp;
 
Code testing in R with the testthat package
 
 
</div>
 
</div>
  
{{Vspace}}
+
{{Smallvspace}}
 
 
 
 
__TOC__
 
 
 
{{Vspace}}
 
 
 
  
{{LIVE}}
 
  
{{Vspace}}
+
<div style="padding:5px; border:1px solid #000000; background-color:#b3dbce33; font-size:85%;">
 
+
<div style="font-size:118%;">
 
+
<b>Abstract:</b><br />
</div>
 
<div id="ABC-unit-framework">
 
== Abstract ==
 
 
<section begin=abstract />
 
<section begin=abstract />
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "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>
{{Vspace}}
+
<!-- ============================ -->
 
+
<hr>
 
+
<table>
== This unit ... ==
+
<tr>
=== Prerequisites ===
+
<td style="padding:10px;">
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "prerequisites" -->
+
<b>Objectives:</b><br />
<!-- included from "./data/ABC-unit_components.txt", section: "notes-prerequisites" -->
 
You need to complete the following units before beginning this one:
 
*[[FND-CSC-Test_driven_development|FND-CSC-Test_driven_development (Test Driven Development)]]
 
 
 
{{Vspace}}
 
 
 
 
 
=== Objectives ===
 
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "objectives" -->
 
 
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>
{{Vspace}}
+
<td style="padding:10px;">
 
+
<b>Outcomes:</b><br />
 
 
=== Outcomes ===
 
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "outcomes" -->
 
 
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>
{{Vspace}}
+
</tr>
 
+
</table>
 
+
<!-- ============================ -->
=== Deliverables ===
+
<hr>
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "deliverables" -->
+
<b>Deliverables:</b><br />
 +
<section begin=deliverables />
 
<!-- included from "./data/ABC-unit_components.txt", section: "deliverables-time_management" -->
 
<!-- included from "./data/ABC-unit_components.txt", section: "deliverables-time_management" -->
 
*<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.
 
*<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.
Line 72: Line 46:
 
<!-- included from "./data/ABC-unit_components.txt", section: "deliverables-insights" -->
 
<!-- included from "./data/ABC-unit_components.txt", section: "deliverables-insights" -->
 
*<b>Insights</b>: If you find something particularly noteworthy about this unit, make a note in your [[ABC-Insights|'''insights!''' page]].
 
*<b>Insights</b>: If you find something particularly noteworthy about this unit, make a note in your [[ABC-Insights|'''insights!''' page]].
 +
<section end=deliverables />
 +
<!-- ============================  -->
 +
<hr>
 +
<section begin=prerequisites />
 +
<b>Prerequisites:</b><br />
 +
<!-- included from "./data/ABC-unit_components.txt", section: "notes-prerequisites" -->
 +
This unit builds on material covered in the following prerequisite units:
 +
*[[FND-CSC-Test_driven_development|FND-CSC-Test_driven_development (Test Driven Development)]]
 +
<section end=prerequisites />
 +
<!-- ============================  -->
 +
</div>
  
{{Vspace}}
+
{{Smallvspace}}
  
  
</div>
 
<div id="BIO">
 
== Contents ==
 
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "contents" -->
 
  
{{ABC-unit|RPR-Unit_testing.R}}
+
{{Smallvspace}}
  
  
{{Vspace}}
+
__TOC__
 
 
 
 
== Further reading, links and resources ==
 
<!-- {{#pmid: 19957275}} -->
 
<!-- {{WWW|WWW_GMOD}} -->
 
<div class="reference-box">[https://cran.r-project.org/web/packages/testthat/testthat.pdf testthat package reference pdf] (on CRAN)</div>
 
  
 
{{Vspace}}
 
{{Vspace}}
  
  
== Notes ==
+
== Contents ==
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "notes" -->
+
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "contents" -->
<!-- included from "./data/ABC-unit_components.txt", section: "notes" -->
 
<references />
 
  
{{Vspace}}
+
{{ABC-unit|RPR-Unit_testing.R}}
  
 
</div>
 
<div id="ABC-unit-framework">
 
 
== Self-evaluation ==
 
== Self-evaluation ==
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "self-evaluation" -->
 
 
<!--
 
<!--
 
=== Question 1===
 
=== Question 1===
Line 123: Line 92:
  
 
-->
 
-->
 
+
== Notes ==
{{Vspace}}
+
<!-- included from "./components/RPR-Unit_testing.components.txt", section: "notes" -->
 
+
<!-- included from "./data/ABC-unit_components.txt", section: "notes" -->
 
+
<references />
 +
== Further reading, links and resources ==
 +
<!-- {{#pmid: 19957275}} -->
 +
<!-- {{WWW|WWW_GMOD}} -->
 +
<div class="reference-box">[https://cran.r-project.org/web/packages/testthat/testthat.pdf testthat package reference pdf] (on CRAN)</div>
  
 
{{Vspace}}
 
{{Vspace}}

Revision as of 19:32, 26 January 2018

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:
This unit will ...

  • ... introduce the testthat package;
  • ... teach how to write tests;
  • ... demonstrate best practice to organize your tests.

Outcomes:
After working through this unit you ...

  • ... can write your own tests;
  • ... can organize your tests in files and a testing directory to simplify running them.

Deliverables:

  • 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.

Prerequisites:
This unit builds on material covered in the following prerequisite units:


 



 



 


Contents

Task:

 
  • Open RStudio and load the ABC-units R project. If you have loaded it before, choose FileRecent projectsABC-Units. If you have not loaded it before, follow the instructions in the RPR-Introduction unit.
  • Choose ToolsVersion ControlPull 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.


 

Self-evaluation

Notes

Further reading, links and resources


 




 

If in doubt, ask! If anything about this learning unit is not clear to you, do not proceed blindly but ask for clarification. Post your question on the course mailing list: others are likely to have similar problems. Or send an email to your instructor.



 

About ...
 
Author:

Boris Steipe <boris.steipe@utoronto.ca>

Created:

2017-08-05

Modified:

2017-08-05

Version:

1.0

Version history:

  • 1.0 New contents
  • 0.1 First stub

CreativeCommonsBy.png This copyrighted material is licensed under a Creative Commons Attribution 4.0 International License. Follow the link to learn more.