Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hello, if a program was not written in a way with proper functions with the given input, what would be the way to write an unit test or integration test, that is the output that is to be compared at the end in a unit test is not contained in a function, should I change the code to contain everything in a function for a particular output that im supposed to get?

What I have tried:

I have tried writing it but have no idea what to call as the value that Im supposed to test is not contained in a particular function taking particular inputs
Posted
Updated 1-Oct-20 23:24pm

The proper way is to treat it as a black box, providing appropriate inputs and checking if expected outputs are produced.
 
Share this answer
 
Testing is an art of its own, but the best way it to test the real release functions and NOT change them, but for testing it is often needed to write a bit more explicit.

When testing functions it makes sense to test all possible input, so include also invalid and error prone values. Like for an integer negative values and null and MAX_INT.
For string input also the empty string, null string and long values are needed.

Read about "Test Driven Development" for further insight like test coverage and integration tests.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900