ABSTRACT

This chapter covers how to write code that tests other code. Readers can also take this kind of approach when testing functions which ideally are the way they write code. As with their normal R script, they can have separate testing scripts (a testing script is a normal R script which people use specifically for testing code but doesn't actually function any different) for each major part of the code that they are testing. As with the R scripts for their code, this is simply a way to organize their work, and doesn't affect the testing. At the start authors have some code that loads the data that they will test this isn't in the setup file since the code is for this specific test script (though it could be in the setup.R file and the results would be the same). In these cases there are relatively few opportunities to use unit tests to check the readers code.