BDD and functional tests

I am starting to buy BDD. Basically, as I understand it, you are writing a script that describes eligibility criteria for a particular story. You start with simple tests, from the outside, using mocks instead of classes that you haven't implemented yet. As you progress, you should replace mocks with real classes. From Introduction to BDD :

First, fragments are implemented using mocks to set up an account on credit or cards are valid. They form points for the implementation of behavior. As you implement the application, givens and the results are modified to use the actual classes that you have, so that by the time the script is complete, they will become the proper end-to-end functional tests.

My question is: when you finish the implementation of the script, should all the classes you use be real, for example, in integration tests? For example, if you use a database, should your code be written to a real (but easy to remember) database? After all, should you have any mockery in your end-to-end tests?

+6
unit-testing tdd mocking bdd
source share
5 answers

Well, it depends :-) As I understand it, the tests produced by BDD are still unit tests, so you should use mocks to eliminate dependence on external factors such as DB.

However, with full integration / functionality tests, you should obviously test the entire production system without any mockery.

+3
source share

Integration tests may contain stubs / layouts to fake code / components outside the modules that you integrate.

However, IMHO, an end-to-end test should mean no stubs / layouts along the way, but only production code. Or, in other words, if layouts are present, this is not exactly an end-to-end test.

+2
source share

Yes, by the time the script runs, ideally all your classes will be real. The script implements the behavior from the point of view of the user, so the system should look like the user sees it.

In the early days of BDD, we used to start with layouts in scripts. I don’t worry about this anymore, because it’s a lot of work to constantly taunt you. Instead, I will sometimes do things like data or the behavior of hard code if it allows me to get feedback from interested parties faster.

We still keep layouts in unit tests.

For things like databases, you can use the built-in database or something else to help you get feedback faster. At some point, you should probably run your scripts on a system as close to production as possible. If it is too slow, you can do it in one night, and not as part of a normal build cycle.

As for what you have to do, writing the right code is much more difficult than writing code. I worry about using my scripts to get feedback from interested parties and users before I worry about how close my environment is to the production environment. When you get to the point that changes take place every two weeks, of course, then you probably need more confidence that you are not introducing any errors.

Good luck

+2
source share

I agree with Peter and ratkok. I think you keep ridicule forever, so you always have unit tests.

Separately, it is appropriate to additionally have integration tests (without layouts, using a database, etc., etc.).

You can even sometimes find useful answers (mock one piece of dependent code (DOC), but not another).

0
source share

I just recently studied BDD and in particular jBehave. I work in fairly large enterprises with a lot of people-oriented waterfalls. I see BDD as a way to use cases in business, and then directly into tests that a developer can then turn into unit tests or integration tests.

It seems to me that BDD is not just a way to help developers understand what a business wants, but also a way to ensure that these requirements are accurately represented.

My opinion is that if you are dealing with mocks, you are doing unit tests. You need both unit testing to verify the details of the classes and integration to verify that the class works well with others. I find that developers are often tied between them, but it’s best to be as clear as possible and keep them separate from each other.

0
source share

All Articles