Stubs and Driver any1?

Im studying the use of stubs and drivers. I basically know what their use is, but im not sure how to use them or implement them. Not understanding the concept fully, Help please :)

thanks.
For stub: if you want to test some function which depends on a incomplete function, let say, bool function.
You may want the bool function first be
1
2
3
4
bool somefunction (some parameters)
{
      return true;
}

Though this is not quite true, but for testing proposes, this should be enough.
Driver is similar to this. You may want to test some function (bool function, for example) but haven't implement the whole project, so you could write your main as
1
2
3
4
int main
{
     assert(somefunction(some parameters));
}

The main function doesn't run the whole project, but could be used to test the "some function".
what is the assert part do or mean?

if i was testing an in function returning a value, how would i do a stub for that?
also a void function since thats what my work is askign for.

so basically a driver is just testing the function in the main() or testing a function(1) within another function(2) and calling fucntion(1) to see if function(2) works?
Last edited on
For info about assert(), see:
http://www.cplusplus.com/reference/clibrary/cassert/assert/

An assert tests a condition and then reports if the condition failed. As written, the assert is asserting that somefunction() returns a non-zero value (0 = FALSE, anything else TRUE).

The standard one usually displays a popup and then triggers a breakpoint. But they could just log the failure and leave the code to continue.

To me, stubs are functions that allow a program to link even though they don't do anything. They're of use when you're part way through implementing something and want to test what else you're written before continuing.

If the "stub" contains a bit of logic so it can pretend to be a real function, then it's often called a mock function, rather than a stub (which is usually totally stupid). But I've also seen these functions (and classes) referred to as fake and dummy.

And a driver function is a stupid function that just calls a function, with the necessary parameters. They're generally used by developers when debugging a new function that isn't yet hooked up. If it starts to do validation, then it's really a unit test (or unit test function), rather than a simple driver function.

Regards

Andy


Last edited on
Thanks you described it very well but i guess im going to need to actually code it to feel confident of what it does.
Topic archived. No new replies allowed.