What is integration testing?

  • Help me understand integration testing. There are a lot of materials on unit testing, but I did not find any sensible examples on integration testing.

    specifically for the task, how can you test the code that:

    • prepares data
    • processes them in a loop
    • distributes the results to different tables

  • Integration testing differs from unit testing:

    Firstly, you will not test each module (class, block) separately, but several modules together. During integration testing (as opposed to unit testing), your IoC containers will not pass mocks (stubs) as dependencies, but real objects. For example, if you are testing a class method that filters objects received from the database, then in the case of unit testing, you will have to exclude working with the real database in order to speed up the test and in order to ensure that the test result will only be checked functionality of the tested class and its specific method.

    Secondly, the fact that integration testing does not necessarily have execution time constraints (in other words, no one needs a unit test that will run, let's say, a minute, which is quite acceptable for an integration test). This is due to the fact that during the integration testing process your code will work, for example, with a real database, the request to which will take a certain amount of time.

    According to your specific example, if the code was originally written so that it can be tested, then, in general, you will have three or four separate classes, each of which will be responsible for performing a specific task (according to the Single Responsibility principle), i.e. ... for data preparation, data processing, data distribution, data recording in the database. Each of these classes should use the functionality of the other class so that it can be easily replaced with another implementation. Those. substitute both a real object of another class and a stub, then integration testing is the same unit testing, but with the transfer of real dependencies. This is where Dependency Injection comes in.

  • It's not clear on what qualifies as a successful test? In the case of unit testing, there is reference data, and we know in advance what we expect from the method. In the case of filtering data from the database, what will be the success criterion? Found / not found? But then what's the point of testing?

  • @zymir The pass/fail criteria of the test depends on the specification - on what result you expect from a particular module, in the case of integration testing - what do you expect as the result of the work of several modules in a bundle. The point of integration testing is to make sure that the modules work correctly in the process of interacting with each other, and not separately. For example, a criterion for the success of testing a class that filters data can be checking what data is found and whether there is extra data there. This is already at your mercy as a developer.

Suggested Topics

  • 3
  • 4
  • 3
  • 3
  • 3