carta / styleguide

Carta's style guides
26 stars 5 forks source link

Folder structure #1

Open bhardin opened 6 years ago

bhardin commented 6 years ago

Discussion on best practice of Folder structure.

wagnerluis1982 commented 6 years ago

I wonder why the subfolder unit. Would be because it should have integration, fixtures, and so on?

bhardin commented 6 years ago

Excellent question. I'm a huge fan of having a single test structure that mimics the root folder. But, we ran into two problems with supporting it.

  1. We wrote our guide to support a legacy code base where tests had no folder structure. The code mixed both styles suggested by pytest. In addition, the /tests folder had a mixture of folder names selected by previous developers. There was no clean and clear way to divide the folder. It became problematic to support a single test directory which mimics the root.

  2. The folders already inside the tests folder had utility. There were factories, fixtures, integration, and browser tests. Developers not used to writing unit tests don't understand what defines a unit test and thus write integration tests when they want to write unit tests. Having a nested structure under the /tests folder allowed us to keep the code that served utility and have "non-unit" writing developers continue contributing to the code base.

jxodwyer commented 6 years ago

What are everyones thoughts on colocating unit tests with our app structure?

For ex:

app/foo/__tests__/test_model.py
app/foo/model.py

This way tests are more in our face and we don't have to go through process of recreating our entire app dir structure under a high level dir of tests.

bhardin commented 6 years ago

We had this structure before, but it created issues:

  1. There was a mixture of tests in the tests/ directory and in the app directory which made things challenging due to no standard.

  2. When apps become tightly coupled (not great, but it is what it is) you begin requiring things in other apps which creates more coupling of tests to folder structure.