Open hedayat opened 5 years ago
If you want something to work with non-abstract classes you can use Spy
, it allows you use FakeIt tools on existing objects : https://github.com/eranpeer/FakeIt/wiki/Quickstart#spying
But as you can see, you need an object for it to work, so the class can't be abstract. Spying abstract classes is a bit hard because we would need to be able to mock the methods (to "un-abstract" the class) before creating an instance of the object, in case any of the abstract method is called in the constructor.
I don't know if the Spy
feature is enough for your needs, let me know if it isn't.
Well, yeah, FakeIt tries to avoid this! However, it has some limitations, which I'm not sure if are solvable reliably. It works fine for interface classes, but it is C++! So, I have an abstract class which does have a constructor, and I want to test its constructor. AFAIK, current FakeIt mocks don't construct an object, so the constructor of the abstract class is not run. So, it seems that FakeIt currently doesn't provide any solutions for mocking such a class without defining a class completely manually.
Therefore, I think having tools to simplify defining mock classes would be nice. Specially considering what modern C++ provides, it seems that it can be even simpler than what is available in some of the current mock libraries: e.g. you might be able to define a mock method with only knowing its name (well, certainly not for overloaded ones, for which you'd also need the signature or at least the number of args).