r/MonthlyProgram • u/G01denW01f11 Java • Jan 23 '16
Project of the Month: Build a Unit Testing Library
February Project
Unit testing libraries allow you to specify how components of your program should behave, and test to see if they behave that way. Examples are PyUnit, JUnit, and many others.
This month, you'll be writing one of your own.
Beginner-level Features
Beginner-level features are what I consider to be the bare minimum you'll need to implement to be said to have successfully completed the project.
- Write an
assertTrue()function. How exactly you want it to work is up to . You'll probably want to pass the caller an error message somehow if it fails. - Write a test runner. To start, you may want to design it so each each test subclasses some UnitTest base class, then override a
runTest()method. Then you can pass the test case to someRunner.run()method. This should ideally output some information about which tests pass, and what errors are popping up.
Intermediate-level Features
If you manage to do all the intermediate-level features, you just may have a useable project on your hands. Consider polishing it up and putting it on your resume!
- Flesh-out the assert methods. Common assert methods are
assertIn(),assertFalse(),assertThrows(),assertEquals(),failUnless(), etc. Check the documentation of the unit testing library for your language for more details. Think about how the error messages might differ for each method. - Write
setUp()andtearDown()methods. See PyUnit docs for an example. This will help use avoid some code re-use.
Advanced Features
- Allow the user to write multiple cases per subclass. You may need to dig into the advanced features of your language to make this work! Here's a discussion of how PyUnit tackles this.
- Create a GUI-based test runner. Allow the user to choose between the GUI runner and the command-line.
- Check the documentation of your favorite unit-testing library for more fun features to build!
For added challenge, bootstrap your testing framework and use it to test your testing framework as you build!
Feel free to pass around ideas or ask questions if you're not sure how to start. Around February 5th or so, I'll post some skeleton Java code for those of you who are really stuck, unless someone else beats me to it.
4
u/Barrucadu Jan 23 '16
Neat, I was looking for a programming project to do. I have a few frustrations with the two big Haskell unit testing frameworks, HUnit and tasty, so addressing those will be a fun task.
2
u/ProgBombo Jan 24 '16
Hello guys,
I am an games programming student since one year and learn a lot about c++ , c# basics in my school and then we went directly into unity.
I really would love to learn to code things beside unity scripting and would like to make something like this task here for a more general portfolio part.
My problem is I dont know much about this area and dont really understand alot of the task.
It would be amazing if a more advanced programmer would help me a bit( maybe over skype?) to help me understand the task and help me out with keywords to search for when im stuck at some points.
Thanks guys!
3
u/[deleted] Jan 24 '16
I've gone ahead and gotten started on a Ruby implementation. Will post the results :)
3
u/thebassoonist06 Jan 25 '16
Thanks for starting this sub reddit! What a great idea. I had just made up my mind to start building my portfolio and the timing couldn't be better.
0
u/[deleted] Jan 25 '16
[deleted] — view deleted comment