Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #30980
| From | Stefan Reuther <stefan.news@arcor.de> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Re: Unit testing frameworks for embedded c |
| Date | 2022-01-26 18:10 +0100 |
| Message-ID | <sss2qa.4q0.1@stefan.msgid.phost.de> (permalink) |
| References | <ssrefj$fcn$1@dont-email.me> |
Am 26.01.2022 um 13:23 schrieb pozz: > I read many comparisons among unit testing frameworks, but sincerely I > can't decide which one to use. > > Do you use any? Which one and why? None. Just <assert.h>. For me, the main objective for a unit test framework is to have some syntactic sugar for assertions and, less important, for grouping tests into test suites and stuff. Do we need assertions? It is surely helpful, if an equality assertion fails, to have expected and actual value presented on a golden plate. On the other hand, getting those values with a debugger isn't much more complex, and you typically fire up a debugger anyway to investigate. In a language such as Java or C++, you can have some higher-level assertions such as "assert-throws" or "assert-container-contains", which save quite a lot of typing. In C, the highest level you could get is something like "assert-string-equals", but the gain compared to plain 'assert(strcmp(...) == 0)' is vanishingly small. Do we need to group tests? People delight in numbers, "I have 937 unit tests, and of those, 936 pass, look how awesome I am!". But, seriously, even if one test fails, the product is broken and someone needs to investigate, so, for me, unit tests produce a "ok"/"nok" result, so I just need a binary that runs or crashes. Now, what I don't expect in a unit test framework proper is the whole area of mocking stuff. In languages like Java, how to mock something is pretty straightforward: you use abstract interfaces, factories, etc., and to mock a file system access, you pass a mock FileSystem object. In C, how you can mock - if you mock at all - depends on your codebase. Do you have the equivalent of virtual interfaces? Do you want to play linker tricks? Do you want to play preprocessor tricks? That decides what mocking framework, if any, you can use. Personally, when I unit-test C, I'm testing computations and logic, which usually don't need mocking. Things like: put in this input, expect this output, from my computational kernel. Stefan
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unit testing frameworks for embedded c pozz <pozzugno@gmail.com> - 2022-01-26 13:23 +0100
Re: Unit testing frameworks for embedded c Stefan Reuther <stefan.news@arcor.de> - 2022-01-26 18:10 +0100
Re: Unit testing frameworks for embedded c pozz <pozzugno@gmail.com> - 2022-01-27 11:14 +0100
csiph-web