I have some C++ code in a package that I want to unit test and I don't want to export to R. I've seen:
Unit tests for code in the /src folder of an R package?
and the code I want to test falls into the second category:
Or you consider your C code to be more standalone, in which case you could use one of a bazillion unit testing frameworks for C.
If one wants to test from C++ (not in using a R framework) what is the best way to setup the test suite? Do you put your C++ tests in tests/
and then have a C++ program with a main somewhere, or do you write a driver function to execute all the C++ tests and then call it from R?
I imagine it is probably a good idea to have the tests be automated by R CMD check
as well, which I'm not clear on how to automate using the R package framework.
Unit testing is a software development and testing approach in which the smallest testable parts of an application, called units, are individually and independently tested to see if they are operating properly. Unit testing can be done manually but is usually automated.
It often makes sense to write the test first and then write as much code as needed to allow the test to pass. Doing this moves towards a practice known as Test-Driven Development (TDD). Bluefruit uses a lot of TDD because it helps us to build the right product without waste and redundancies.
Unit tests in isolation One of the benefits of unit tests is that they isolate a function, class or method and only test that piece of code. Higher quality individual components create overall system resiliency. Thus, the result is reliable code. Unit tests also change the nature of the debugging process.
I do not follow:
Can you clarify your question a little more?
Maybe you just want to express your C++ code in a way that lets Rcpp call it from only the unit tests so that you get results you can then test via one of popular R unit testing frameworks. In which case the answer may be very similar to what any one of the (currently) 276 Rcpp-using packages on CRAN do as many do in fact use unit tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With