Posts

Showing posts with the label testing

Code coverage report generation for dotnet core applications

Image
In "Working Effectively with Legacy Code" Michael Feathers introduced a definition of legacy code as code without tests, since a code without tests is difficult to maintain, extend and evolve. It doesn't matter if you are using the latest technologies, if you don't test your code, it will hard to change without breaking anything, which will make it rigid and difficult to maintain. Remember that unit tests are the base in the testing pyramid. In order to ensure that you are covering with unit tests the most important part of our application, code coverage can be helpful to detect where you have lack of tests. Code coverage is a tool offered by products like ReSharper or the Enterprise version of Visual Studio . However, these products are not free and you might not want to pay for this essential feature. But if you are working with dotnet core, it is quite easy to get a code coverage report thanks to ReportGenerator package. In order to generate your tests, first...

Use Visual Studio extension to distribute your Code Snippets

Image
Introduction In a previous post we saw how you can build code snippets to write tests faster empowering your team to follow good practices.  https://www.albertocorrales.com/2018/10/writing-unit-tests-faster.html In this post, we will see how we can distribute our snippets with a Visual Studio extension, which offers different advantages, for example: You encapsulate your snippets in a VS extension, you you don't need to distribute them independently, and developers don't need to add them to VS one by one.  The extension can be updated improving he current snippets or including new snippets. You can add more functionality in your Visual Studio extension.  Creating a new Visual Studio extension First of all, if you have never developed a Visual Studio extension, you might need to install Visual Studio extension development kit. To do it, install this option in your Visual Studio Installer Create a new Visual Studio extensions project. For this example, I...

Writing unit tests faster

Image
Introduction When you are writing tests, the name of the test is very important because the person who is executing the test should be able to detect what was fine or wrong at a glance. For this reason, it is a good practice to follow the convention format: TestedMethodName_InputData_ExpectedResult By using this format, we can see in a line the method to test, the input used and the result expected, so it will be easy to identify what was wrong. Another good practice is following the "Arrange", "Act", "Assert" convention ( http://wiki.c2.com/?ArrangeActAssert ), so when we are reading a test, we can identify easily each part of the test. To make more visible each part, unit test usually include one comment per each state of the test. Finally, if you are using different test categories, for example to classify unit tests and integration tests, you should use the word TestCategory("YourCategory") in your metadata definition. Using the ...

Improvement in the Test Explorer for Visual Studio v15.7

Image
The next Visual Studio update (v15.7) will include an improvement in the Visual Studio Test Explorer that will allow us to see the best organized tests. So far we are seeing them like this: And with the improvement we can see them organized in a hierarchical way, grouped by project, namespace, class and method. This will also facilitate the execution of a set of specific tests (for example if we only want to launch those of a specific class). This is how the explorer test will look in future versions: Although in Visual Studio the test categories already existed ( https://msdn.microsoft.com/en-us/library/dd286683.aspx ), it is good news that by default we are grouped together in a much more practical way. This information is based on the article https://blogs.msdn.microsoft.com/visualstudio/2018/03/21/visual-studio-2017-version-15-7-preview-2/ and since it is not a version in production, you might experience some changes. Happy coding!!

Introducción a los Tests End-to-End en Angular 5

Image
¿Qué son los tests e2e? Los tests e2e (end-to-end) son utilizados para poder probar si determinados flujos de tu aplicación están funcionando correctamente desde el inicio hasta el final. El propósito de los tests e2e es identificar dependencias y asegurar que la información es correctamente intercambiada entre componentes y sistemas. Los test e2e no reemplazan a los tests unitarios, pero son fundamentales para asegurar que los flujos de la aplicación no se rompen al integran nuevos cambios y tienen un papel fundamental en la Integación Continua. En el caso concreto de las aplicaciones Angular, Protractor ( http://www.protractortest.org ) nos ofrece un framework que nos permite ejecutar tests e2e en un navegador real, como si un usuario estuviera navegando por nuestra aplicación. ¿Cómo funciona Protractor? Protractor es un programa node.js que soporta los frameworks de testing Jasmine y Mocha. Normalmente en Angular Jasmine es el framework más popular ( https://jasmine.git...