Git Product home page Git Product logo

unittest's Introduction

unittest

This is a concise, TAP-compliant, R package for writing unit tests. Authored tests that can be run with R CMD check with minimal implementation overhead.

The unittest package provides a single function, ok, that prints "ok" when the expression provided evaluates to TRUE and "not ok" if the expression evaluates to anything else or results in an error.

If you are writing a package see the "I'm writing a package, how do I put tests in it?" section in the package documentation.

The package was inspired by Perl's Test::Simple.

If you want more features there are other unit testing packages out there; see testthat, RUnit, svUnit.

A very simple example of usage

You have a simple function in the file myfunction.R that looks something like this

biggest <- function(x,y) { max(c(x,y)) }

To test this create a file called test_myfunction.R in the same directory containing

library(unittest, quietly = TRUE)

source('myfunction.R')

ok( biggest(3,4) == 4, "two numbers" )    
ok( biggest(c(5,3),c(3,4)) == 5, "two vectors" )    

Now in an R session source() the test file

source('test_myfunction.R')

and you will see the test results. That's it. Now each time you edit myfunction.R re-sourcing test_myfunction.R reloads your function and runs your unit tests.

Installing from CRAN

In an R session type

install.packages('unittest')

Installing the latest version directly from GitHub

Linux

In an R session type

pkg_file <- tempfile()
download.file(url = 'https://github.com/ravingmantis/unittest/archive/master.tar.gz', mode = 'wb', method = 'wget', destfile = pkg_file)
install.packages(pkg_file, repos = NULL, type = 'source')

Mac OSX / Windows

Assumes that the CRAN package downloader is installed.

In an R session type

library(downloader)
pkg_file <- tempfile()
download(url = 'https://github.com/ravingmantis/unittest/archive/master.tar.gz', mode = 'wb', destfile = pkg_file)
install.packages(pkg_file, repos = NULL, type = 'source')

unittest's People

Contributors

hennesseya avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.