For Java land, I prefer to organize in the approach prescribed by Maven and Gradle's defaults. However, I don't have a separate .test
sub-package instead I keep to the same package when I am unit testing the component (that way I don't have to make methods public
if I don't need to and rely on default
visibility. Secondly in Java land the tools are preconfigured to handle that scenario by default.
Following up to the above... regardless of what language, I package by functional group by default and by types for common utilities. This is different than what most JavaScript and other code generators do, which lump everything by type and is propagated by insert negative adjective of choice developers.
Granted that I do that for TypeScript/Javascript, Python land where the source is the executable, I would keep unit tests with the file they are testing with with the .test.ts
suffix. This keeps the tests close to the code and you'd know the test is for the code because their base names are exactly the same.
Composite tests where you test multiple components are also kept in the same spot as the code since one of the root module where the test starts from would be in the same folder anyway. There's no need to make one test file per module if the module files are very coupled.
BDD/TDD tests, I would keep it in a __test__
sub-folder since that's Jest's default. These tests try out multiple components and are related to a business transaction rather than a simple sanity of testing different inputs to handle component edge cases.
You can tell a BDD/TDD test vs a unit/composite test in that your describe()
is generally a business scenario rather than the module name.
The good and bad part about JavaScript is its very much a free for all. Every framework does things their own way. I stuck with what by react-native-builder-bob
uses since I write react native libraries.
<root>
|- src/ (sources)
|- /__test__/ (tests only)
|- lib/commonjs/... (generated output)
|-/module/... (generated output)
|-/typescript/... (generated output)