Script Library: 1241 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: brianwisti

Documentation for: test-simple.r


Test Simple

test-simple.r is a simple testing module, as the name suggests. My goal with this library is to simplify software testing for those who are new to the subject. It will follow the pattern set by Perl's Test::Simple module  rather than the more involved xUnit testing style. Use the excellent REBOL Unit  if you prefer the xUnit style of testing.

Test Driven Development

Test Driven Development, or TDD , is an approach to writing programs that is focussed on code quality and robustness. This focus usually results in code that is easier to maintain. It often has the surprising effect of making development time much faster in the first place, because you are defining what the program does in small steps as you write each test. Many TDD developers start out with only a rough outline of what their code should do, refining it in their tests as they go along.

TDD in 3 Easy Steps

  • Make a test that fails.
  • Make the test pass.
  • Refactor your code to eliminate redundancies and improve aesthetics.

This is also called the Red-Green-Refactor cycle, mainly because it's a little snappier. One of your best resources for TDD might be Test-Driven Development  , by Kent Beck. It is aimed towards the xUnit style of TDD, but the ideas are all still very useful. And I won't be offended if you end up going towards xUnit rather than test-simple. As long as you are trying to maintain and improve the quality of your code, I'm happy.

test-simple.r in Action

Here is a basic test script. I am working on getting better examples together as time allows.


 do %test-simple.r

 good-test: make test [
         name: "Good Tests"
         ok     [ 1 == 1 ]
         ok/log [ 1 == 1 ] "All is right in the world."
         wrapup
 ]

 bad-test: make test [
         name: "Bad Tests"
         ok     [ 1 == 2 ]
         ok/log [ 1 == 2 ] "Something is very wrong!"
         wrapup
 ]