Debugging testthat tests in RStudio

Is it possible to call a debugger in RStudio when running testthat tests? I was not able to find an installation that allows this (various combinations of "use the functions of the devtools package, if available" in the settings, clicking "Test package" in the menu "Create → Advanced", running test() in the console, inserting calls to browser() , etc.), but have not yet found a way.

I am also very much lost in testing, not knowing whether the code was run in the system libraries (by creating "Build and Reload") or is running in place from the local R directory, or something - sometimes RStudio complains that the breakpoint is not can be installed until the package is restored (so I suspect the first one) or not (so I suspect the last one). Not sure if this question is closely related or not related to my main question.

Finding no way to get into the debugger, I end up inserting the test code into the console and working in a very special way, and basically remove the TDD habits in the leg. Therefore, any advice will be appreciated - if it is not possible to call the debugger, any suggested workarounds?

I am running RStudio version 0.99.447 on OS X, in local mode, with R 3.2.1.

Change I would also like to know more about the options, for example. "option X will never support debugging because it works in a forked process, try using another option Y instead."

Refresh - without replying here, I also asked https://support.rstudio.com/hc/communities/public/questions/204779797-Debugging-testthat-tests-in-RStudio (where I also found “t were the answers).

+8
debugging r testing rstudio testthat
source share
1 answer

The following works for me:

  • Insert a browser() call somewhere in the testthat test.
  • Run devtools::test() from the RStudio console (instead of using the "Test Package" menu item from the user interface)

Then, when the test runner hits the browser() call, you can use the environment browser and go through the code.

I have not found a way to make testthat stop at breakpoints, but inserting browser() invocations is a pretty close replacement.

To be absolutely sure that you start with a consistent state when it comes to downloading packages, you can close RStudio, reopen it, run Clean and devtools::test() , and then devtools::test()

Finally, if you are working in the RStudio package, you can check out the following RStudio support tip:

To effectively debug your package, you must also ensure that your package is compiled with the --with-keep.source option. This parameter is standard for new packages in RStudio; if you need to install it manually, it can be found under Tools → Project Settings → Build Tools.

+5
source share

All Articles