Struggling with the implementation of Automation tests

HI all I just wanted to update this so if anyone else is struggling with Spec tests my experience might help. My code will probably not be the best way but it worked for me :slight_smile: (in UE 5.3)

So for my test I had create a character C++ class that can shoot and an ammoComponent C++ class which is attached to character. I then made a blueprint of the character and assigned my projectile in there.

The tests i wanted to run were:
What’s the ammoComponent’s max ammo at the start? should be 30
What’s the ammoComponent’s ammo count at the start? should be 30
What’s the ammoComponent’s ammo count after a shoot has been fired? should be 29

To start with I was trying to spawn my character class during the test and the first two tests would pass but the last would fail, it turned out this was because I was spawning my C++ class where the projectile wasn’t assigned (doh). After realising this I assigned my projectile class in the character’s constructor and success.

I still wanted to try this out with the projectile assigned in blueprint so commented out where I was assigning it in the C++ class. After a lot of trial and error and help from Francesco over at Automated Testing With Specs in Unreal Engine | Francesco’s GameDev Corner (minifloppy.it). I managed to spawn in the blueprint class using a soft class pointer and the FSoftClassPath function in my BeforeEach function.
image
image
I then spawned the BP character
image

For my first test (with the C++ character) I was creating the world using Francesco’s World Fixture but in the second (with the BP character) I created the world with UWorld::CreateWorld and then destroyed the world in the AfterEach function. Both of these way seemed to work without issue.

Feel free too look at the full code over at:

Now onto another test type :slight_smile: