Writing Tests in Drivers and Feedback (MCP9808)
geo_leeman
Posts: 190
I'm coming at micro programming from a more Pythonic style data analysis background, so the first thing I wanted to do when writing an object to deal with sensors was write a test-suite for it (to go with the demo). I was curious if there is (which is likely the case) a much more standard/accepted way to test/demo/document your SPIN objects, but this seemed like a reasonable thing to try to do... Test every function and verify it's operation while showing how to use it. I'd appreciate any thoughts or feedback on this approach since I'd like to make sure all of my publicly available code is actually useful to folks. I've attached a screenshot of the demo program output and the code is in a zip file (or on GitHub here). Hmm... That temperature reading seems a bit cold even for a chilly northern day in the shop... I'll have to look at that and see what might be going fishy.
(I can move this to accessories if that's more appropriate, but seemed like a general programming style question to me.)
(I can move this to accessories if that's more appropriate, but seemed like a general programming style question to me.)
Comments
Nice coding!
Don't expect much in the way of software engineering practices around here.
As far as I can tell most objects in OBEX come with some kind of demo wrapped around them which shows how to use it and exercises it's functionality. Which is a good start.
Thanks! There was actually a small error in the way certain temperature values were handled, but I've got it solved now... and my space heater on!
Well, I'm going to try to make sure things I produce have tests I suppose. A lot of the embedded folks probably don't need them, but I don't trust myself... I've seen my code sometimes! It would be great if there were some kind of unit testing framework though!
I'll probably post on the OBEX, but I (like many others) seem to be putting most things on GitHub these days. Admittedly it doesn't handle spin files very well right now.
Erlend
Thanks! I did have an issue with the temp conversion though. I just finished testing it below 0C (thanks to mother nature and cooling spray) and looks like it works a treat now. I'll comment the fixes and put it in the GitHub repo tomorrow, so be sure to use that version! Glad someone will get the benefit of not having to write this!
I remember when I wrote my draft code for this chip - I had to dig deep into my brain to recover what I learnt about binary coding of after-the-comma digits. I learnt it at the age of 16 and have not needed it since. Until now. Kindof nice to know that something I learnt four decades ago - in the digital domain - still is 'current'.
Erlend
I almost feel like unit tests are MORE important in embedded since we are more often interacting with and changing the physical world than a typical desktop developer. It would be great if there were a SPIN testing framework that is a bit nicer than my hacky implementation here, but it does do the trick.
Another nice thing about testing is that it provides the base of tests to go with when setting up your production testing (if that's a thing for your product). I have never done anything high volume, but my instruments are for geophysical applications, so they have to work and have to have good field tests to flag issues.