Вопрос по – В чем разница между интеграцией и юнит-тестами?

273

Я знаю так называемое учебное определение юнит-тестов и интеграционных тестов. Что мне любопытно, так это когда пора писать модульные тесты ... Я напишу их, чтобы охватить как можно больше наборов классов.

Error: User Rate Limit ExceededWordError: User Rate Limit ExceededWordError: User Rate Limit ExceededSentenceError: User Rate Limit ExceededWordError: User Rate Limit ExceededSentenceError: User Rate Limit ExceededWord... по крайней мере, в тех местах, где они взаимодействуют.

Have these tests essentially become integration tests because they now test the integration of these 2 classes, or is it just a unit test that spans 2 classes?

Error: User Rate Limit Exceeded

Я неправильно понимаю интеграционные тесты, или на самом деле разница между интеграцией и модульными тестами очень мала?

Edit

Error: User Rate Limit Exceeded

Ваш Ответ

18   ответов
4

8

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededareError: User Rate Limit Exceededexcept for their granularityError: User Rate Limit Exceeded
3

12

1

Error: User Rate Limit Exceededorg.junit.AssumeError: User Rate Limit Exceeded

4

1

Error: User Rate Limit Exceeded

43

Unit Testsindividual componentunitHtmlSanitizer

Integration TestshowHtmlEditControl

61

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

17

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
4

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

22

Unit tests use mocks

Error: User Rate Limit ExceededSentenceError: User Rate Limit ExceededWordError: User Rate Limit ExceededWordError: User Rate Limit ExceededSentenceError: User Rate Limit Exceeded

Error: User Rate Limit ExceededexternalError: User Rate Limit ExceededunitError: User Rate Limit ExceededsimulatedError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
269

integration tests

Unit test

not

public SomeResults DoSomething(someInput) {
  var someResult = [Do your job with someInput];
  Log.TrackTheFactYouDidYourJob();
  return someResults;
}

DoSomethingverifycommunicate

Feature: To be able to do something
  In order to do something
  As someone
  I want the system to do this thing

Scenario: A sample one
  Given this situation
  When I do something
  Then what I get is what I was expecting for

Business Value.

DoSomething

public SomeResults DoSomething(someInput) {
  var someResult = [Do your job with someInput];
  FakeAlwaysWorkingLog.TrackTheFactYouDidYourJob(); // Using a mock Log
  return someResults;
}

Log.DoSomething(). Fortunately, the Gherkin spec will find it and your end-to-end tests will fail.

Log[Do your job with someInput][Do your job with someInput]

Log

they are telling the truth.

DoSomethingLogit's clearly lying

DoSomething()[Do your job with someInput]

A system with a broken class

A single bug will break several features, and several integration tests will fail

The same bug will break just one unit test

All your features using the broken Log are red All your unit tests are green, only the unit test for Log is red

The difference

whatguessing where

where

.

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededcanError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
4

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

10

The nature of your tests

unit test

integration testbetween

Risk reduction: That's what tests are for. Only a combination of unit tests and integration tests can give you full risk reduction, because on the one hand unit tests can inherently not test the proper interaction between modules and on the other hand integration tests can exercise the functionality of a non-trivial module only to a small degree. Test writing effort: Integration tests can save effort because you may then not need to write stubs/fakes/mocks. But unit tests can save effort, too, when implementing (and maintaining!) those stubs/fakes/mocks happens to be easier than configuring the test setup without them. Test execution delay: Integration tests involving heavyweight operations (such as access to external systems like DBs or remote servers) tend to be slow(er). This means unit tests can be executed far more frequently, which reduces debugging effort if anything fails, because you have a better idea what you have changed in the meantime. This becomes particularly important if you use test-driven development (TDD). Debugging effort: If an integration test fails, but none of the unit tests does, this can be very inconvenient, because there is so much code involved that may contain the problem. This is not a big problem if you have previously changed only a few lines -- but as integration tests run slowly, you perhaps did not run them in such short intervals...

some

Pragmatic approach to using both

0

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

2

Simple Explanation with Analogies

Integration Tests

Unit Tests

Example:

Let’s take a car as an example. Integration test for a car: e.g. does the car drive to Woop Woop and back? If it does this, you can safely say that a car is working from an overall view point. It is an integration test. If it fails you have no idea where it is actually failing: is it the radiator, transmission, engine, or carburettor? You have no idea. It could be anything. Unit test for a car: Is the engine is working? This tests assumes that everything else in the car is working just fine. That way, if this particular unit test fails: you can be very confident that the problem lies in the engine – so you can quickly isolate and fix the problem. Using Stubs

Suppose your car integration test fails. It doesn’t drive successfully to Echuca. Where is the problem?

Now let us suppose that your engine uses a special fuel injection system and that this engine unit test has also failed. In other words, both the integration test and the engine unit test have failed. Where then is the problem? (Give yourself 10 seconds to get the answer.)

Is the problem with the engine, or with the fuel injection system?

1

Have these tests essentially become integration tests because they now test the integration of these 2 classes? Or is it just a unit test that spans 2 classes?

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Похожие вопросы