8
What is the concept of driver and stubs in integration tests, what is the difference between them?
In what situations should be used?
8
What is the concept of driver and stubs in integration tests, what is the difference between them?
In what situations should be used?
4
Driver and Stub are stuntmen (doubles, also known as mocks), whose function is to replace a component during automated or non-automatic software testing.
If we talk about the level of automated tests implemented by the programmer himself, the explanation of stub and other stuntmen can be seen here: What’s the difference between mock and stub?
But note that at this level of automation, where we use frameworks xUnit and we write the tests in the same language we use to write the production code, the Driver.
The kind of stuntman Driver is used in tests of "black box", which are tests performed not on the source code but against the external interfaces of the system, such as web forms or HTTP Apis.
Consider an architecture where a component To depends on the component B. Component B does nothing alone - it is only consumed by component A.
Maybe you want to:
This leaves you with 3 possible test scenarios (image taken from Quora):
1) The component To is tested by consuming the component B real, so that the two components are tested in this scenario.
2) When testing the component To, dependence B is replaced by a double (a substitute component, used only during testing). In this scenario only the component To is being tested.
3) The component B is being tested alone without your consumer, who has been replaced by a double. In this scenario, only the component B is being tested.
In this example, the component To is the consumer, the orchestrator of the operation being tested. If I want to test it independently (or if I simply don’t have the dependency yet available), I replace this dependency with a Stub, which must provide pre-programmed ready responses.
Now, if the focus of the test is precisely dependence, the component B, I replace the consumer with a Driver, which will try to simulate the consumption of the tested component.
To better assimilate this example, we can think of the component To as being a smartphone app and the component B as being a HTTP API consumed by this application.
So when you go to test the application, instead of consuming the actual API (for example a complex backend system) you create a stunt that replicates the API in question by providing ready-made answers. This API stunt would be a Stub.
And when you’re going to actually test the API, you replace the mobile app with software that simplifies and even automates HTTP requests. This other software would be the double of the type Driver.
You can use them when testing one component when the other is not available (it is an external resource, has high complexity, has relevant cost to be consumed, is not yet ready, etc.) or even when it is available but you do not want your behavior to affect the test results of another component.
The classification Driver appears more in the universe of QA (Quality Assurance).
It does not appear at the level of automated tests in style xUnit because, in an analogy, the Driver would be the unit test code itself, which doesn’t need a special name - it’s just the test code :-)
2
Integration test is the phase of software testing in which modules are combined and tested in a group. It succeeds the unit test, in which the modules are tested individually, and precedes the system test, in which the complete (integrated) system is tested in an environment that simulates the production environment.
In the context of integration testing, we use the elements stubs and drivers
As can be seen by its name, using the Top-down technique, the test starts from the highest level to the lowest, that is, the highest level components are integrated first. The test uses driver and stubs:
Perks
Disadvantages
Integration is done from the most basic level of the hierarchy. Stubs are not always needed.
Perks
Disadvantages
Reference:
Browser other questions tagged software-engineering testing
You are not signed in. Login or sign up in order to post.
Stub already has here: http://answall.com/q/36745/101
– Maniero