I searched some for TDD tutorials this week. and found a few. Unfortunately, I found tutorials with no or very little “hands on” practice. So I am still looking for good tutorials. When I find some, I will post links on this blog.
What I have gleaned from the tutorials so far is that when building your code, you replace your main file with your testing file(s) so that the tests can call each of the functions/methods individually with known values and should get back predictable results.
Embedded Units Testing:
For embedded systems unit testing, my code will be compiled to run natively on the development machine rather than being compiled for the target processor. This means a different tool chain for test build than for production or debug builds.
Note: Tool Chain is the set of tools that are used to create machine runnable code from your source files.
Any API call or peripheral device needs to have mock code that can be run as part of the tests.
Note: Mock Code is software that represents things that are not on your testing machine, or would hinder testing.
I had to decide what a “Hello World” project would look like in unit testing. Since I don’t know who is reading this, I decided the simplest thing I can do is a C project that would run natively on my PC. My tool chain is the Gnu Compiler Collection(GCC). It is already installed on many Linux distros and is easy to install of both Windows and Mac. If you don’t have it just do a web search for <your OS> GCC install.
Then I searched for C++ unit testing in eclipse. I found that I had to update eclipse which required downloading and re-installing. I installed version 4.6.2. I then installed Cute C++ unit Testing Easier from the Eclipse marketplace.
In the eclipse overview screen there is now a link to “learn more about Cute”. I went there.
I clicked on the tutorial link in the eclipse help viewer for cute. I followed through the tutorial to see how far it would get me. After ctrl-alt-F(Tutorial said to do this) didn’t do anything for me. Then I tinkered for a while, and I finally got the tests to run and fail as expected. In another tutorial in the eclipse help files, it says to right click, and select New Test Function. This also didn’t work.
I have an environment set up that I can start writing tests in and of course some kind of code to test. This “Hello World” project took much longer to get started than I thought it would.
Have you had to deal with software development tools that didn’t work like the tutorial? Have you used Cute plug in for Eclipse? I’d love to hear about it. I am just learning about TDD/Unit testing, do I have a realistic understanding of TDD/Unit Tests?