jueves, 14 de julio de 2016

Unit Test How start with it?

All the programmers have a technique to test the software than they made.
In some cases this technique is print in console the result of a things or test the functionality with examples in the interfaces, but this method cannot be effective.
For our lucky, in some language we have a very effective method, during this two week I discover a very effective method, the Unit Test.
The unit test is a good method to test the functionality of the class methods in your program. So, I have some important points that you need to know if it is your first time with unit test. So go ahead.


Correct Configuration


The magic of the unit test is the correct configuration of the necessary files, if you don’t have it, the test is going to fail, even if the sentences that you can test is simple. For example, test that the true sentence is true or compare a simple string. When it happen you need to review the dependence of your project. Try to change the angular dependence mock and animate, for the same version of angular. It resolve the problem with the fail test without reason.

Know how testing

This is an interesting topic, because, how do know what you need to testing? So, it’s really easy, only what you need is to know what your module do and test what do you need that the methods in the module do. If you have problems with this you can use the coverage of PhantomJS, it is very effective to see the percentage of the functionality test and to know how is not testing yet


Using Spy

Yes, nobody like to be spy, but in this situation is good. The spy option of jasmine allow you see what the object methods do and permit to test if it is called. So, use it with trust. In this case the SpyOn method in Jasmine is your friend.

Create Mocks

Angular have a library special to create a false function or data to be testing, this is usefel when you need test a service that is used in the controller o when you have your data in a database. Tne name of the library is ngMocks,is important to remember when installe the ngMocks is that the version have been the same version of Angular. You can configure this in your karma file.


All this things are simple and necessary to be a unit tester. If you need to learn more about it, you need to practice and search information about unit testing, for your lucky, the web have more information about it.

No hay comentarios:

Publicar un comentario