Test
usethis::use_testthat()
		

  • Add test files in testthat folder, the names should starts with test
  • test for equality
  • # test_getRand.R
    context("Test functions in getRand.R ...")
    library(myPackage)
    
    test_that("test getRand ...", {
    	set.seed(42)
    	expect_equal(getRand(1), 0.914806, tolerance = .0001)
    	expect_equal(getRand(2), c(0.9370754, 0.2861395), tolerance = 0.0001);
    })
    
    test_that("test getRandN ...", {
    	expect_equal(getRandN(1, 2), 1.660895, tolerance = 0.0001)
    })
    		
    # test_getHello.R
    context("Test functions in getHello.R ...")
    library(myPackage)
    
    test_that("test getHello ...", {
    	expect_identical(getHello(), "Hello World!")
    })
    		

    devtools::test() # implement test
    		
    Reference
  • Package ‘testthat’