简体   繁体   中英

What is the difference between unit, integration and end-to-end tests in Angular?

  1. What is the difference between Unit, Integration and End-to-end testing in Angular?
  2. Which the principles or paradigms should I know to implement each kind of these tests, how it works?

I found out that unit testing is for component class, integration testing is for component's class and template together.

But I didn't find how does end-to-end testing differ from these ones, how can I implement them in Angular, which are the principles and paradigms for these types of testing.

These types of tests are not different just because you use Angular. Their usage is pretty much the same regardless of which framework you use.

I will try to explain

Unit

Is when you test only a certain isolated unit of code

Example:

var sum = function(firstVal, secondVal){ 
    return firstVal + secondVal;
}

Here we could use unit test to verify that this code actually does sum the firstVal and secondVal.

expect(sum(3,5)).toEqual(8);

Integration

Is when you test an integration, some code you usually interact with but don't have control over

Example:

Let's say you are using a third party api in your application which exposes a GET method that calculates the sum of two values. Here we could use integration test to verify that our external api, which we don't have control of, really work as it say it will.

request("http://someapi/sum?firstVal=3&secondVal=5", function(error, response){
  expect(response).toBe(8);
});

End-to-end

Is when you test the complete application, from one end to the other end.

Example: Start of by being the user and use the application from the web UI. Then verify that all the actions that have been triggered by the webUI has been performed correctly. For example if you create an order from the gui, verify that the order has been created all the way down to the the database or at the third party integration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM