Hello everyone! I’ve been having a bit of a problem with testing that I can’t seem to find any information on anywhere online, and it’s to do with Unreal’s automation testing. For reference I am using Unreal Engine 4.27.2.
Basically, I have been trying to use the Automation Test system for the first time, and have had trouble testing my main character pawn. What I want to be able to do is to access the controller to carry out key/controller presses during the test. I have tried to get the APlayerController from the world (World->GetFirstPlayerContoller()), from the pawn (Pawn->GetController()), and creating a new one from scratch (UGameplayStatics::GetPlayerController(World, 0)), however these all return a null pointer.
I don’t know if there is another way of doing this I am missing, or there is an extra step in setting up the world I am missing, or maybe this is only possible in blueprints which I haven’t looked at yet. I feel like I could expose the pawn’s protected functions that the controller presses call to public, but this feels like bad practice and something that I shouldn’t need to do for testing.
As mentioned previously I can’t find anything on this topic so any advice would be greately appreciated.
You’re saying you want your automated test to be NOT automated?
I believe in the automated test framework, there is no concept at all of you as a player. It’s just code that is running without any inputs from you.
If you want to simulate inputs etc, that is typically done via Mockups or something similar, which yes typically requires that either you expose stuff or define friend test classes that can call internal class methods. (Not sure in UE5 since it’s so undocumented as you mention).
If you really want the ability to walk around and push buttons DURING your test, that’s not really automated testing, that is end user testing. I haven’t tried that yet but I wish you luck.
If you are using the original input system in UE then there are a few options for something like this.
If you want to do this in an automated C++ unit test from the Automation test framework you can have a look at the “InputTestFramework.cpp” file from the Enhanced Input plugin. This provides some ways that you can spawn a “Controllable Pawn” actor in a blank UWorld to test your action mappings. The way that you map the inputs here would be different, but the general gist of it is pretty much the same.
Alternatively (and perhaps a little bit better) would be to make a functional testing map.. This will be a small level that you can place a custom “test controller” in that inherits from your game’s player controller which you can then add to in order to make some functions that call “InputKey” or “InputAxis” on the player controller.
You can then make some test completion states for your test map, like “Complete the test when the player walks over this box collider” or “Complete the test when this wall gets shot”. Then you can test your gameplay behavior by adding inputs.
If you choose the use Enhanced Input (which I would recommend), then you can just call the “Inject Input for Action” function on the Enhanced Input subsystem, which will let you inject “fake” input values for the player to process. This combined with the above functional tests means that you can do the whole thing in blueprints!