1
votes

I am in the process of trying to implement codeception in a fairly large project at the moment and the default flat directory layout that codeception uses is not viable as we will have too much tests squashed into one directory.

Codeception uses the following structure:

tests/
- _data
- _output
- _support
- acceptance
- functional
- unit

We are trying include the tests in our mvc application structure so we could have the following:

application/
-  controllers/
       - folder1/
            - controller1.php
            - test.php
       - folder2/
            - controller2.php
            - test.php
-  views/
      - view1/
            - view1.php
            - test.php
      - view2/
            - view2.php
            - test.php

This way the structure makes it a bit easier to follow for us as otherwise we will end up with 1000s of tests in one folder. I am aware that we can define sub namespaces within the main codeception.yml however it still uses the same flat directory layout which we don't want to use.

What would a codeception bootstrap look like to get it to look into the top level folder and just run any test within directories below it and include it in the main runner?

1

1 Answers

1
votes

I would recommend NOT to include the tests into your application business code, because they simply offer no functionality to you app. Tests should always be in their own scope.

You find the default codeception structure confusing with a larger amounts of tests. I ran into the same problem, but for the solution you have to remember one thing: You're not bound to the structure:

  • acceptance
  • functional
  • unit

You can create as many test suites as it suits your need (the defaults are only suggestions). Feel also free to mix unit and functional test in one suite. I ended up creating many small suites for the different cases i want to test:

  • suite1/
    • controllertest1.php
    • viewtest1.php
  • suite2/
    • controllertest2.php
    • viewtest2.php If this suites end up to small I would put the tests for 1 module of your application into 1 suite. Don't forget to name the testcases with expressive names. It make your life a lot easier.

Simply create a new suite with ./codecept g:suite suite1 http://codeception.com/docs/reference/Commands#GenerateSuite