mercredi 8 avril 2015

AngularJS what should be tested

So me and my team are creating a web application and we are doing this:



  • one of them is responsible for the API:

    • the api will serve the UI, will provide it with data and has the possibility to provide the fields the UI wants, sorted and everything, basically it filters all the data so the UI does not have to.



  • Another one is responsible for the UI:

    • The UI will consume the API and present the data



  • I am doing the test but i am doing the tests after the code. I test both the API (phpunit - unit tests and integration tests) and the UI (jasmine - unit tests and protractor - e2e tests)


So what should I really test?


Most of the controller functions on angularJS are fetching data and assign it to the $scope so are these functions worth to unit test?


Example of controller:



UnidadesOrganicasService.getUnidadesOrganicas().then(function (unidadesOrganicas) {
$scope.unidadesOrganicas = unidadesOrganicas;
}, function errorCallback() {
$scope.showToastError('Occorreu um erro a carregar as unidades orgânicas!');
});


The other methods are making basically the same with some if's that depends on the data that comes from the API.


service method:



this.getUnidadesOrganicas = function () {
return Restangular.all("unidades-organicas").getList({"sort": "acronimo"});
};


So the test would be like this:



  • mock the data with the $httpBackend

  • check of the scope has the correct mocked data, but this would result in something like this: expect($scope.something).toEqual(MockedSomething); and the http mock would be just this: $httpBackend.expectGET('/something').respond(MockedSomething);


I know that E2E tests on the UI are very important but in this case are the unit tests worth to make for this kind of methods? Or should I just test the really important methods like calculus methods and methods like that?


On the other hand in the API most of the features seems irrelevant to make integration tests and unit tests seems much more important.


My real question is if I am thinking right and some orientation on what to test in this case.


Aucun commentaire:

Enregistrer un commentaire