BeforeAll and AfterAll in Automation Spec?

I have an automation spec which tests a component.
To test the component, I create a new world, spawn an actor, add the component to the actor in BeforeEach method.

All that happens for every test which slows tests down.

I wanted to know if there are functions that run before all tests and after all tests.

That way, I can create the world, use that world for all tests, and then destroy the world when all tests are done.

Try this, it shows how to group unit tests into a container so you can do setup/takedown tasks in each container rather than for every test:

1 Like

I’m already using it (I’m even mentioning it in the title).
It doesn’t have a function that runs before and after all tests.

Pretty sure my comment here was incorrect. Removed to avoid confusing others.

I’m also looking for a way to do this. My thought was to force BeforeEach and AfterEach to act like BeforeAll and AfterAll by only sometimes running their code blocks.

For BeforeAll, you can check whether it’s already been run by keeping a list of corresponding FString names, for example, so you only run it the first time it is encountered.

AfterAll is harder, because I don’t know how many tests to wait for until it should be called. I thought about having an It(“should clean up”) test as the very last test in that Describe() scope that calls the AfterAll code, but I don’t think the spec format guarantees the order of test execution.