How to add your own reporter to testthat

testthat

#1

Hi all,

I need a reporter that gets the results of a testthat test file into JSON format. I'd like to write my own reporter for that, but don't find any documentation on reporters in testthat. Alternatively, if I can use eg the ListReporter or JUnitReporter and convert from there to JSON, that would be nice too. But I'd like to avoid that, as this needs to be incorporated in live code testing for an online teaching system.

Anyone ideas?


#2

Can you take the ListReporter in reporter-list.R in testthat, rename it to MyListReporter (in two locations) and use it from your package, e.g. via devtools::test(reporter = MyListReporter)? You should then be able to adapt it to your needs.

Reporters are R6 classes that inherit from the Reporter base class, see e.g. https://cloud.r-project.org/web/packages/R6/vignettes/Introduction.html for an introduction to R6. You can override all methods in Reporter, see reporter.R.


#3

Thx for the tip and the directions to the relevant files. I'm going to experiment a bit and see how far I get.

Much appreciated!