Unit Test Code architecture.

Hello!

I’m a Unity developer new to Unreal and I want to make my code “ready” for unit testing to begin with, to not run into problems later.
Now I am aware of the Humble Object pattern, but the setup requires lots of classes at different places, which is why I’d love to hear what the most practically solution might be.
Let me list the solutions I have in my head:

Solution 1: Do not abstract logic and Actor classes at all. Issues: Some functions trigger animations that need to be completed to continue (unit testing needs to go around them), + lots of potential issues with the UE4 classes.

Solution 2: Classic Humble Object pattern:


class IFoo
{
     virtual void doUeStuff() = 0;
};

class AFoo : public IFoo
{
     void doUeStuff() override
     {
          // Actually do it
     }
};

class MockFoo : public IFoo
{
     void doUeStuff() override
     {
         return;
     }
};

class FooController
{
    IFoo* foo;
  
   void doStuff()
   {
     foo->doUeStuff();
   }

}



Issues: Lots of code for 1 class.

Solution 3: Provide NULL pointer to foo in FooController in test. Instead of declaring the interface + implementing a mock class, the pointer just gets checked for NULL. Issues: Overhead with the “if (foo)” check every time? But very handy IMO.

I’m a bit unsure what the best layout is to use, also does UE4 provide any kind of mock framework? Or are solution 2 or 3 absolutely okay to use?

Edit: If I decide to use an interface, does a simple interface as stated above do or do I need an UInterface?

Have you made any progress on this? Any updates?

UE5 does not have a mocking framework as far as I am aware. They recently added in the automation spec features with Describe and It.

More info on automation: Automated Testing at Scale in Sea of Thieves | Unreal Fest Europe 2019 | Unreal Engine - YouTube