-
What is the concept of driver and stub in integration tests, what is the difference between them?
-
In which situations should be used?
What is the concept of driver and stub in integration tests, what is the difference between them?
In which situations should be used?
Driver and Stub are doubles , also known as mocks component during software testing, whether automated or not.
If we talk about the level of automated testing implemented by the programmer himself, the explanation of the stub and other stunts can be seen here: What is the difference between mock and stub?
But note that at this level of automation, where we use xUnit frameworks and write the tests in the same language we used to write the production code, the Driver does not appear.
The driver type Driver is used in "black box" tests, which are tests performed not on the source code but on the external interfaces of the system, such as web forms or HTTP APIs.
Consider an architecture where an A component depends on the B component. 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 ):
In this example, the A component is the consumer, the orchestrator of the operation being tested. If I want to test it independently (or if I simply do not have the dependency still available), I replace this dependency with a Stub , which should give preprogrammed ready answers. >
Now, if the test focus is just the dependency, the B component, I replace the consumer with a Driver , which will try to simulate the component tested.
To better assimilate this example, we can think of the A as being a smartphone app and the B component as > HTTP API consumed by this application.
So when you're going 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 actually test the API, you replace the mobile application with software that simplifies and even automates Http requests. This other software would be the Driver stunt.
You can use them when testing a 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 Driver rating appears more in the QA universe.
It does not appear in the level of automated testing in xUnit style because, in an analogy, the Driver would be the unit test code itself, which does not need a special name - it is just the tests: -)
Integration Test is the software test phase in which modules are combined and group tested. It follows the unit test, where the modules are individually tested, and precede the system test, where the complete (integrated) system is tested in an environment that simulates the production environment.
In the context of integration testing, we use the stubs and drivers
As you can see from the name itself, using the Top-down technique, the test starts from the highest level to the lowest level, ie the highest level components are integrated first. The test uses driver and stubs:
Advantages
Disadvantages
Integration is done from the most basic level of the hierarchy. Stubs are not always needed.
Advantages
Disadvantages
Reference: