0

I have a question on how to implement behat/mink functional tests. In my web app, I have users that can access some data sheets if they have the required credentials (i.e. no access/ read only / write).

I want to be able to test all the possible contexts via behat/mink. The question is what is the best practice for such testing ? Some dev told me that I have to create a scenario for each type of user I would like to use. Then, I will have to use the user I created in others tests. But I am not very confortable with this idea : I believe that it introduces coupling between my tests. If the test that creates the user fails, then the test that checks the access over my datasheet for that specific user will also fail.

So, I believed that I could use some fixtures : before testing my app, I run a script that will insert me all the profiles I need. I will have some tests dedicated for creating users, and I will use the fixtures to check if a specific user is allowed to access a specific datasheet. The counterpart with this solution is that I will have to maintain the fixtures set.

Do you have any suggestion / idea ?

Guiguiboy
  • 1
  • 1

1 Answers1

1

Hi user3333860 (what a username XD),

I'm not an expert in testing and these days, I'm more on ruby/rspec but I personally think that both solutions are good and are used.

Use a feature to create your User: If your test for creating a user fails, It may means that your User creation refactoring is also messed up. So the fact that other tests fails doesn't seems to be a drawback to me. But I do understand the fact that you don't want to have coupling between your tests. The main point is, are your test ran in a static order or are they run randomly (ie: rspec don't always launch tests in the same order) and are you ready to have the same test run multiple time in different features so that your other tests can successfully complete.

Use a fixtures: Well it is also a good and popular solution (in fact, the one I use) and you already pinpoint the fact that you will have to maintain.

In the end, I'd take the fixtures path ONLY with a tools helping like FactoryGirl that helps you maintain your objects templates (here is the PHP version of it) https://github.com/breerly/factory-girl-php

Hope I helped with your dilemma.

nekogami
  • 326
  • 2
  • 5