I’ve read some articles that suggest you to write one unit test per methdo to evaluate on your class.
Using IMPLEMENT_SIMPLE_AUTOMATION_TEST
that would be something similar to:
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FExampleFeature01,
"Example.feature01", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)
bool FExampleFeature01::RunTest(const FString& Parameters)
{
// Implement test
TestEqual(TEXT("Checking feature 01"), ...);
return true;
}
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FExampleFeature02,
"Example.feature02", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)
bool FExampleFeature02::RunTest(const FString& Parameters)
{
// Implement test
TestEqual(TEXT("Checking feature 02"), ...);
return true;
}
...
But in the Engine’s code there are some tests that are written in a way that IMPLEMENT_SIMPLE_AUTOMATION_TEST
is used to test various methods of a class.
For example in StringViewTest.cpp
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FStringViewTestCtor, TEST_NAME_ROOT ".Ctor", TestFlags)
bool FStringViewTestCtor::RunTest(const FString& Parameters)
{
// Default View
{
FStringView View;
TestEqual(TEXT(""), View.Len(), 0);
TestTrue(TEXT("View.IsEmpty"), View.IsEmpty());
}
// Empty View
{
FStringView View(TEXT(""));
TestEqual(TEXT(""), View.Len(), 0);
TestTrue(TEXT("View.IsEmpty"), View.IsEmpty());
}
// Constructing from nullptr is supported; nullptr interpreted as empty string
{
FStringView View(nullptr);
TestEqual(TEXT(""), View.Len(), 0);
TestTrue(TEXT("View.IsEmpty"), View.IsEmpty());
}
// Create from a wchar literal
{
FStringView View(TEXT("Test Ctor"));
TestEqual(TEXT("View length"), View.Len(), FCStringWide::Strlen(TEXT("Test Ctor")));
TestEqual(TEXT("The result of Strncmp"), FCStringWide::Strncmp(View.GetData(), TEXT("Test Ctor"), View.Len()), 0);
TestFalse(TEXT("View.IsEmpty"), View.IsEmpty());
}
// Create from a sub section of a wchar literal
{
FStringView View(TEXT("Test SubSection Ctor"), 4);
TestEqual(TEXT("View length"), View.Len(), 4);
TestEqual(TEXT("The result of Strncmp"), FCStringWide::Strncmp(View.GetData(), TEXT("Test"), View.Len()), 0);
TestFalse(TEXT("View.IsEmpty"), View.IsEmpty());
}
...
My question is, what’s the proper way to write this tests?