Showing posts with label tclunit. Show all posts
Showing posts with label tclunit. Show all posts

Thursday, April 7, 2011

GUIDE: TDD unit testing tools for Tcl

As promised in http://shloemi.blogspot.com/2011/03/tdd-tools-for-tcl.html here is my experience with tcltest package and eclipse.


The story
Suppose we have a function called 'bits_serialize'.

This function should serialize a given data into bits_per_io bits per package (for examples see the tests below and what they return).

This function have the following signature:  bits_serialize {bits_per_io description}, where:
  • bits_per_io
    • How much bits each package have.
  • description
    • a pair of {data bits}, where:
      • data 
        • the data we want to serialize.
      • bits
        • the size, in bits, we want to serialize this data.
let's test this function using tcltest...

Test code
# Generated using http://pygments.org/
source unit-under-test.tcl ;# contains the definition of bits_serealize 

test base--always-ok {This is as simple as it gets.} -constraints {
} -setup {
} -body {
 return TRUE
} -cleanup {
} -result TRUE

test bits_serealize--partial-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0x01 16 "]
} -cleanup {
} -result [list 1]

test bits_serealize--full-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0xFFFFFFFF 32 "]
} -cleanup {
} -result [list [ format "%u" 0xFFFFFFFF ]]

test bits_serealize--over-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0x060504030201 64 "]
} -cleanup {
} -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ]]

test bits_serealize--way-over-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 " 0x060504030201 320 "]
} -cleanup {
} -result [list [ format "%u" 0x04030201 ] [ format "%u" 0x0605 ] 0 0 0 0 0 0 0 0]

test bits_serealize--cross-quanta {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 "
  0xFF 1
  0xFF 2
  0xFF 3
  0xFF 4
  0xFF 6

  0x04030201 32
 "]
} -cleanup {
} -result [list [ format "%u" 0x201FFFF ] [ format "%u" 0x403 ]]

test bits_serealize--quanta-and-half {description here...} -constraints {
} -setup {
} -body {
 return [bits_serealize 32 "
  0xFFEEDDCCBBAA 48
 "]
} -cleanup {
} -result [list [ format "%u" 0xDDCCBBAA ] [ format "%u" 0xFFEE ]]


eclipse-unit-testing

Results

++++ base--always-ok PASSED
++++ bits_serealize--partial-quanta PASSED
++++ bits_serealize--full-quanta PASSED
++++ bits_serealize--over-quanta PASSED
++++ bits_serealize--way-over-quanta PASSED
++++ bits_serealize--cross-quanta PASSED
++++ bits_serealize--quanta-and-half PASSED

My impression 

I definitely recommend using this unit!! and to my surprise eclipse supports it built in (see picture ==>).

Tuesday, March 29, 2011

GUIDE: tclunit/TDD for Tcl, usage and examples.

As promised (tdd-tools-for-tcl.html) here is my humble experience/research with tclunit.

Guides / tutorials found



Research results

Usage example

Have fun...

Friday, March 25, 2011

TDD unit testing tools for Tcl

After committing my first 'big' feature to my current employee, I got a feeling that something was left behind in the heat of the rush. That think was, of course, the new code test coverage.

That lead me to try and find tools / guidance for Tcl TDD.

Here are the things I've found for Tcl:

  1. A very good TDD tutorials found
    1. http://www.agiledata.org/essays/tdd.html
    2. http://geosoft.no/development/unittesting.html
  2. TDD tools for Tcl
    1. Wiki comparison of available tools for Tcl -  http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#Tcl
    2. tclunit - http://www.tcl.tk/man/tcl8.4/TclCmd/tcltest.htm
      1. Download here - http://sourceforge.net/projects/tclunit/

Thats all, not much. I intend to check tclunit, experience with it and report back later on... see Y'a.