UE4 and unit tests

Started by
3 comments, last by R 7 years, 1 month ago

Hi, I'm trying to separate my logic into a different source set that I can unit test, I could set up a project with the unit tests correctly, but I don't know how to make unreal *see*, my other sources folder.

Any ideas or examples on how this should be done, also, if this is not a correct approach and I'm doing everything wrong, couyld you please shed some light?

Advertisement

Create a new Module for your tests, add the Module you want to test as a dependency of your test module. You'll have to give it access to privates, which means exposing your classes with an export declaration.

In addition to the advice of having a module for testing, keep in mind exactly what unit tests are meant to test.

Unit tests are test of the tiniest individual pieces of functionality. They should never hit other systems or rely on external systems; those are different, possibly integration tests or feature test depending on what they are testing.

Be sure to research the topics of dependency injection, fake objects, and mock objects. You will likely need to replace other systems in UE4 with mock objects so your code will use those fakes and mocks instead of the actual system.

Unreal has out-of-the-box helpers for several kinds of automated testing.

Thanks for the replies and recommendations, I actually know a lot about software development and testing, but not that much about unreal and its tools. I hacked a solution where I can write "logic" code that's uncoupled from unreal in another project and I can run unit tests on those. Later in I'll take a look at the unreal test tools, seems to be very interesting.
Thanks again, thisnis my first post and I feel very welcome! :D
Thanks, I will take a look at those ideas, I have a ton of experience with software development but 0 with unreal and green development, all the help I can get is very appreciated!
I just came up with a hack solution where I build the game logic code without anything unreal and run the tests against those files by creating a cmake project that takes the files straight from that folder. It's working fine so far, but I think the modules solution is the way to go.
I'll probably take a look at the unreal testing tools some day, but for now I'll just use Google test and Google mock because that seems to be standard knowledge I can use in any c++ project and not only with unreal.

This topic is closed to new replies.

Advertisement