Tests doesn't show in Frontend Automation

Ok I tried to implement Test and the long story short it doesn’t show up in editor.

Here is code:

class GameEffectsTestSuite
{
	UWorld* World;
	FAutomationTestBase* Test;

	AGACharacterAttributeTest* SourceActor;
	UGAAttributeComponent* SourceComponent;

	AGACharacterAttributeTest* DestActor;
	UGAAttributeComponent* DestComponent;

public:
	GameEffectsTestSuite(UWorld* WorldIn, FAutomationTestBase* TestIn)
		: World(WorldIn),
		Test(TestIn)
	{
		SourceActor = World->SpawnActor<AGACharacterAttributeTest>();
		SourceComponent = SourceActor->Attributes;
		SourceComponent->DefaultAttributes = NewObject<UGAAttributesTest>(SourceActor->Attributes);
		SourceComponent->GetAttributes<UGAAttributesTest>()->Health.SetBaseValue(100);
		SourceComponent->GetAttributes<UGAAttributesTest>()->Energy.SetBaseValue(100);
		SourceComponent->GetAttributes<UGAAttributesTest>()->Stamina.SetBaseValue(100);

		DestActor = World->SpawnActor<AGACharacterAttributeTest>();
		DestComponent = DestActor->Attributes;
		DestComponent->DefaultAttributes = NewObject<UGAAttributesTest>(SourceActor->Attributes);
		DestComponent->GetAttributes<UGAAttributesTest>()->Health.SetBaseValue(100);
		DestComponent->GetAttributes<UGAAttributesTest>()->Energy.SetBaseValue(100);
		DestComponent->GetAttributes<UGAAttributesTest>()->Stamina.SetBaseValue(100);
	}

	~GameEffectsTestSuite()
	{
		// run after each test

		// destroy the actors
		if (SourceActor)
		{
			World->EditorDestroyActor(SourceActor, false);
		}
		if (DestActor)
		{
			World->EditorDestroyActor(DestActor, false);
		}
	}
	void TestEqual(const FString& TestText, float Actual, float Expected)
	{
		Test->TestEqual(FString::Printf(TEXT("%s: %f (actual) != %f (expected)"), *TestText, Actual, Expected), Actual, Expected);
	}

	void Test_SetBaseValue()
	{
		float value = SourceComponent->GetAttributes<UGAAttributesTest>()->Health.GetFinalValue();
		TestEqual(TEXT("Attribute Base Value"), value, 100);
	}

};
class FGAAttributesTests : public FAutomationTestBase
{
public:
	typedef void (GameEffectsTestSuite::*TestFunc)();
	TArray<TestFunc> TestFunctions;
	TArray<FString> TestFunctionNames;

	FGAAttributesTests(const FString& InName)
		: FAutomationTestBase(InName, false)
	{
		ADD_TEST(Test_SetBaseValue);
	};
	virtual uint32 GetTestFlags() const override { return EAutomationTestFlags::EditorContext | EAutomationTestFlags::SmokeFilter; }
	virtual bool IsStressTest() const { return false; }
	virtual uint32 GetRequiredDeviceNum() const override { return 1; }

	virtual FString GetBeautifiedTestName() const override { return "System.GameAttributes.Attributes"; }
	virtual void GetTests(TArray<FString>& OutBeautifiedNames, TArray <FString>& OutTestCommands) const override
	{
		for (const FString& TestName : TestFunctionNames)
		{
			OutBeautifiedNames.Add(TestName);
			OutTestCommands.Add(TestName);
		}
	}
	bool RunTest(const FString& Parameters)
	{
		TestFunc TestFunction = nullptr;
		for (int32 i = 0; i < TestFunctionNames.Num(); ++i)
		{
			if (TestFunctionNames[i] == Parameters)
			{
				TestFunction = TestFunctions[i];
				break;
			}
		}
		if (TestFunction == nullptr)
		{
			return false;
		}
		UWorld *World = UWorld::CreateWorld(EWorldType::Game, false);
		FWorldContext &WorldContext = GEngine->CreateNewWorldContext(EWorldType::Game);
		WorldContext.SetCurrentWorld(World);

		FURL URL;
		World->InitializeActorsForPlay(URL);
		World->BeginPlay();

		// run the matching test
		uint64 InitialFrameCounter = GFrameCounter;
		{
			GameEffectsTestSuite Tester(World, this);
			(Tester.*TestFunction)();
		}
		GFrameCounter = InitialFrameCounter;

		GEngine->DestroyWorldContext(World);
		World->DestroyWorld(false);
		return true;
	}
};
1 Like

Is there any thing above that first line? Did you get this from somewhere that was not created by the UE4 wizard?

I actually copied most code from GameplayAbilities module.
I will paste the rest of the code though I’m not sure if it is relevelant.

You need to add:

namespace
{
	FYourClassTest FYourClassTestAutomationTestInstance(TEXT("FYourClassTest"));
}