Reputation: 347
I have just attended my first lesson on cppUnit testing in school and it's quite crazy that I have to write a c++ program and also come up with unit test as well for my assignment.
I am quite lost of
1) how to write a cppUnit testing
2) what kind of things should be included inside the unit test for my program.
assuming I have program that allows a user to
1) requires the user to login to the system first.
after they have log in they can do the following things
2) add a sales transaction to a text file
3) edit a sales transaction from a text file
4) remove a sales transcation from a text file
4) display sales transcation
5) print sales transcation for current day
I have seen many examples online and most of the unit test examples shown are all related to formulas like(+ - \ *).
I not sure if I am correct to say this but correct me if I am wrong, are test units used to test basically on whether a formula is working correctly in a program?
so things like e.g(in my program) "adding a sales transaction to a text file" does not have anything to do with formulas like(+ - \ *) and should be excluded?
Please advice.Thanks in advance.
Upvotes: 0
Views: 116
Reputation: 217145
Unit Tests are for testing part of your application
So for your example:
- requires the user to login to the system first.
You may create an "empty" system
then input some login and test if login is successful or not. (which character are valid in login)
- add a sales transaction to a text file
- edit a sales transaction from a text file
- remove a sales transaction from a text file
Check that the file content is expected after each transaction what's happen when we try to edit/remove when there is no transaction ?
- display sales transaction
- print sales transaction for current day
You may redirect output into some file and compare them...
Note that you would focus on some part (Does you need to check that the display respects some formatting or just testing if the list of transactions is correct suffice ?).
Upvotes: 1