0

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.

2
  • 1
    unit tests have nothing to do with formulas; they are supposed to show that your code behaves within the specification. for simplicity's sake, imagine you were writing a web application - you could write a dozen tests that show that regardless of what site you request you are redirected to the login page before access and reach the site if you have logged in, that you can only log in with valid credentials, etc. Commented Jan 7, 2014 at 7:17
  • thanks for your explainations Commented Jan 8, 2014 at 6:57

1 Answer 1

1

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 ?).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.