Testing idea

When should you start setting up the legalities (entity, meet with an attorney, set up an accountant) when you are just starting to test out a business idea. A lot of that stuff requires money and if you are just starting, you don’t have any kind of track record with your idea. Is there a testing-out phase that can happen and then get all that stuff set up? If you pay all this money and realize you need to pivot products or company ideas, then that money might be wasted.