stub a function with the class I am testing.

7 views
Skip to first unread message

ramyanee

unread,
Oct 11, 2024, 3:33:53 AM10/11/24
to cpputest
Hi folks

need help achieving this: I am testing class Myclass with member functions A and B such that A calls B. 

A()
    ret = B();
}

I need alternate values for ret, I need B to ret something I want. Can this be done? I know how to stub functions from a separate class but i am stuck here.

Both A and B are public.

James W Grenning

unread,
Oct 11, 2024, 9:16:47 AM10/11/24
to cpputest

Hi

One way: Subclass and override...

Make B() virtual.
Make a class that inherits the original class and override B() for test.

You can also do it with the linker. But you need to split B() into a separate file.

If you need to do this, you likely have a design problem.

Cheers, HTH, James

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/7db1e6ac-d599-4f31-a4d7-a019f9c9eacen%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages