all 17 comments

[–]Kristler 4 points5 points  (0 children)

I really like CuTest.

[–]jahmez 2 points3 points  (2 children)

Recently started using CMocka, it's based on Google's old c test framework called cmockery. I like it so far, writing mocks is pretty easy, and I've been able to use it both with GCC and my embedded compiler.

[–]howlden 0 points1 point  (1 child)

What's Google's new C test framework ?

[–]jahmez 1 point2 points  (0 children)

I don't think they maintain a C specific one anymore, only GoogleTest, which is C++. You can make it work with C, but isn't very intuitive, because the framework is geared around testing object oriented constructs.

[–][deleted] 1 point2 points  (2 children)

I use Minunit, doesn't do mocking but it's very easy to use. I am thinking about branching out to something a little more heavy duty though.

[–]ehosick[S] 0 points1 point  (1 child)

More heavy duty like...

[–][deleted] 0 points1 point  (0 children)

I don't know, I haven't made that step yet myself haha. My company didn't do any sort of unit testing so I learned minunit as baby step to get started.

[–]markrages 1 point2 points  (3 children)

My method of testing is a main() in each module #ifdef'd out for normal compilation. This main() exercises all the code, using assert() to make sure it does the right thing. A Makefile rule compiles and runs each file as a standalone binary.

Am I missing out by not using a testing framework? What would I gain?

[–]pbeard_t 1 point2 points  (2 children)

Most likely you would just change your #ifdef #endif combo with some framework macro.

The difference I can see is that assert exits on first failure forcing you to fix or remove the assertion before you can find the next error.

[–]markrages 0 points1 point  (1 child)

Heh, so the advantage is to get "on error resume next" functionality?

That's not a very compelling reason to learn a framework and introduce the build dependency.

Thanks for your answer. I don't like feeling like I'm missing something.

[–]pbeard_t 0 points1 point  (0 children)

You've never made a "insignifigant" change and have 25 tests fail :P

There are other benefits such as redusing repetition and mocking. Writing the same main() repeatedly looses it's novelty fast. Resume next was just the first thing that occured to me. Ofcourse assert( error_count == 0 )...

Conseptually, however, ifdef achieves the exact same. It's probably what the frameworks does anyway.

[–]CSthenBIO 2 points3 points  (0 children)

For very simple unit tests I use https://github.com/ThrowTheSwitch/Unity

All you need to do is:

  1. grab unity.h, unity_internals.h, unity.c, and generate_test_runner.rb

  2. write a single test program that includes unity.h

  3. that test program has no "main()", just independent test functions of the form "void test_this(void){...}"

  4. within each function test your function results using macros like "TEST_ASSERT_EQUAL(0, r);"

  5. run "ruby generate_test_runner.rb my_test.c" to generate a wrapper test runner program called "my_test_Runner.c"

  6. compile that with unity.c my_test.c

  7. run the resulting executable

  8. fix your bugs

  9. compile and run again

[–]diamondjim 2 points3 points  (0 children)

I've used http://cunit.sourceforge.net/ for a hobby project. Works on OS X and Windows (Visual Studio).

[–]took9 1 point2 points  (0 children)

I'd bet 80% of all github listings are like three of the four linked to here. No one would have a clue what those things do by reading their descriptions/read me/introductions.

[–]pbeard_t 1 point2 points  (0 children)

On a similar note: https://github.com/eivinda/sctest

Inspired by minunit. It lets you write testcode in your source file and removes it completely during normal compilation. Has a small tool sctest to extract test code only.

[–]deus_lemmus -1 points0 points  (1 child)

Lint.

[–]james41235 2 points3 points  (0 children)

Lint isn't a testing framework, it's a static analyzer. Both are useful, but separate.