Hey everyone! I'm diving deeper into programming and I'm curious about test file organization. Specifically, I'd love to know the best practices for keeping my test files in the repository. Should they be included in the 'main' or 'production' branch, or is it better to keep them only in development branches? What's the most common or recommended approach in professional environments? Thanks for the help!
5 Answers
It's generally a good idea to organize your folder structure so you have a 'src' folder for your main code and a 'tests' folder for your test files. Keeping everything in the main branch is pretty common practice.
Absolutely, your test files should be in the same branch as the code they correspond to. This way, if you are testing a certain feature, the tests will be right there ready to go. Directory structure can vary by language, but being in the same branch is essential.
I don't think there's any reason to keep tests out of the main branch. Just keep it straightforward and don't overthink the organization. Tests can definitely go in the main branch without any issues.
You should definitely push your tests to the main branch so that they run automatically when the CI/CD pipeline kicks in. Just remember that even if tests are in the main branch, the actual released code doesn’t include them. For organization, it's common to see them in a 'tests' directory at the top level alongside 'src'.
Tests should be included in all branches. Typically, you would have a 'tests' directory that mirrors your 'src' directory's structure, ensuring everything is easy to find and relate back to its corresponding source code.

Yeah, this method works well especially if you're using languages that follow this structure, like Java. Keeping tests in the main branch means they are closely related to the source code and makes things easier.