You basically need one case structure, where every case corresponds to one state. Each state also contains a logic, which decides when and how a transition takes place. For example, if an error occurs inside your "run" state, you can capture this error and a boolean gets the value "true". If the test however is finished without errors then another boolean can get the value "true". Depending which variable changed first, you can programm the logic (for example with a selector) and select the next state to be either "Idle", or "Shutdown". There are many ways to do this and as altenbach mentioned, there are templates available.
The whole case structure should be placed inside a while structure, so that when one state is finished, the new is selected and updates the case structure which runs again. The last state can also be used to stop the while loop, so that the whole VI terminates.
And yes, state machines can run for extended periods of time.