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.
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.
This seems to work as a before all for my tests, BeforeEach is run once for my first It function then not run again for the second It function. For a AfterAll, I read that latent Its will run after the AfterEach so, assuming you don’t have any latent tests, I’d have though you could use a Latent It (or possibly LatentAfterEach) to run after everything else. You could probably also nest a AfterEach with the last It function to run at the end again not 100%.
Don’t quote me I’m a noob I had hoped putting the Before and After Each outside of the describe would work but doesn’t seem too