jeudi 12 juillet 2018

Laravel - Match test directory to app directory

I have a pretty big Laravel 5.6 application I'm currently developing. By default, Larvel comes with a tests directory along with a tests/Unit and tests/Feature sub directories.

  • When I first started developing my app, any test I wrote that didn't require a full HTTP life cycle to take place, I would put in the tests/Unit directory.

    • Example: Testing a custom local query scope on a model.
  • Similarly, any test that did require a full HTTP life cycle I would put in the tests/Feature directory.

    • Example: Testing controllers using a GET, POST, etc request and making sure I got back a 200 response or equivalent.

Now that my application has grown to be quite massive, I'm starting to think that their should be a better way to organize my tests directory. I'm also noticing that parts of my code base do not have test coverage based on reports from codecov.io.

In my mind, it would make sense to create a tests/App directory and have that mirror all my files and classes in the app directory of the project root. Each class and/or file would have a corresponding test. This way, I'll have a better idea of which parts of my app have test coverage and which ones do not. I haven't seen any other projects that do this so I'm hesitant to apply this approach.

So my questions are:

Are there any pitfalls with structuring the tests directory exactly like the app directory?

Is there an alternative way to structure your test directory so that you can tell with ease which classes/files have corresponding tests?

Side Note: I'm well aware that my unit tests don't adhere to the "normal" convention of mocking out your dependencies and testing in isolation. This is a separate issue but in short I feel that mocking doesn't allow you to refactor you code with ease. More info on what I'm talking about in my defense: https://www.youtube.com/watch?v=LdUKfbG713M

Aucun commentaire:

Enregistrer un commentaire