![]() ![]() You can then look at the results to see which lines of your code are never touched by a test, and gives you the opportunity to reflect on if you’ve tested the most important, highest risk, or hardest to program parts of your code. ![]() It’s very useful to verify that your tests test what you think they’re testing.Ī great way to do this is with “code coverage” which runs your tests and tracks every line of code that is run. You can learn more about snapshot tests at. This makes the test fragile if it fails it’s unlikely to be your fault, and fixing the failure is unlikely to be within your control. That suggests this test isn’t particularly useful: if this output changes, it’s much more likely to be the result of change to Shiny than the result of a change to your code. If you look at how the inputs become the outputs you’ll notice that most of the output is generated by Shiny and only a very small amount is the result of your code. It’s worth contemplating the output here before committing to this as a test. You either need to fix the bug that causes it to fail, or if it’s a deliberate change, update the snapshot by running testthat::snapshot_accept(). If the output later changes, the test will fail. # sliderInput01() creates expected HTML Code sliderInput01("x") Output x ![]() Here we use expect_snapshot() to capture the output displayed on the console: The key idea of snapshot tests is to store the expected results in a separate file: that keeps bulky data out of your test code, and means that you don’t need to worry about escaping special values in a string. Test_that ( "as.vector() strips names", ) #> Test passed □īut the presence of quotes and newlines requires a lot of escaping in the string - that makes it hard to see exactly what we expect, and if the output changes, makes it hard to see exactly what’s happened. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |