C unit tester

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
lastcraft
Forum Commoner
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London

C unit tester

Post by lastcraft »

Hi.

I doubt if C coding gets a big following here, but this should at least explain why SimpleTest got a little stalled ;).

I wrote a pure C (actually C99) unit tester with mocks called Cgreen. It's at...
http://www.lastcraft.com/cgreen.php
http://sourceforge.net/projects/cgreen/

It means you can now do stuff like...

Code: Select all

static void drops_line_ending_from_word_and_stops() {
    will_return(stub_stream, 't');
    will_return(stub_stream, 'h');
    will_return(stub_stream, 'e');
    will_return(stub_stream, '\n');
    assert_string_equal(read_paragraph(&stub_stream, NULL), "the");
}
Here we are testing read_paragraph() with a mock function called stub_stream().

The Cgreen unit tester has the usual bunch of assertions, expectations and reporting options. Also, if you are running more than one test (the norm), each runs in a separate process. Wouldn't want seg faults stopping the test run.

yours, Marcus
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Cool stuff Marcus, too bad I don't do C anymore. :D
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Really cool. But perhaps we're not the target demographic. ;-)
lastcraft
Forum Commoner
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London

Post by lastcraft »

Hi...
Ambush Commander wrote:Really cool. But perhaps we're not the target demographic. ;-)
Yeah I know, but I had no one else to tell :cry:.

yours, Marcus
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Hmm... where to get the word out...

You could try some newsgroups on C as well as on unit-testing...
lastcraft
Forum Commoner
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London

Post by lastcraft »

Hi.

Just to say, released a new version with a different mock syntax...

Code: Select all

int my_callback(int i, char *s) {
    return (int)mock(i, s);
}
In the test you can set up an expectation like so...

Code: Select all

expect(my_callback, want(i, 7), want_string(s, "Hello"));
My last unprompted post here about Cgreen, I promise.

yours, Marcus
Post Reply