title: How to produce jUnit fie with R testthat
body: <p>I have R code (not a package) which I would like to cover with acceptance tests using testthat with output being used in Jenkins.</p>
  
  <p>I can start with two files which demonstrate the code structure:</p>
  
  <pre><code># -- test.R
  source("test-mulitplication.R")
  
  # -- test-mulitplication.R
  library(testthat)
  test_that("Multipilation works ", {
    res &lt;- 5 * 2
    expect_equal(res, 10)
  })
  </code></pre>
  
  <p>After the run I would like to get an xml file with results per test file or all tests in a single file.</p>
  
  <p>I noticed there is a <code>reporter</code> capability within testthat, but most of it seems to be internal to the package. It is not clear how to save test results and how flexible is the functionality. </p>
  
  <p>Unfortunately documentation on that part is not complete. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have now found a way to test the directory with better syntax and option for junit output:</p>
  
  <pre><code># -- tests/accpetance-tests.R
  options(testthat.junit.output_file = "test-out.xml")
  test_dir("tests/")
  
  # -- tests/test-mulitplication.R
  library(testthat)
  test_that("Multipilation works ", {
    res &lt;- 5 * 2
    expect_equal(res, 10)
  })
  </code></pre>
  
  <p>This I believe produces an XML object inside the reporter, but I still don't see how to save it to a file. </p>
  
  <p>I tried to wrap the <code>test_dir</code> call with <code>with_reporter</code>, but that does not do much.</p>