Pages

Showing posts with label Code Snippet. Show all posts
Showing posts with label Code Snippet. Show all posts

Monday, August 28, 2017

Haz tu propio C# snippet para generar Unit Tests

El objetivo de los 'snippets' es evitarnos el tener que teclear lo mismo cada vez, y si tu estas actualmente haciendo Unit tests, no estas ya cansado de escribir  arrange, act y assert ?

Si eres como yo, entonce la respuesta es SI. y no solo eso sino que hay otras areas en las que podemos mejorar nuestra experiencia de programacion. Asi que toma esto como un ejemplo introductorio a los snippets, y creemos uno para nuestro unit test.

Lo que queremos lograr es que con un par de teclas podamos obtener esto:


Y que el cursor se enfoque en la parte WhatAreWeTesting (que estamos testeando)  de el nombre de la funcion para que podamos cambiarla, luego con un TAB para a la parte 'ExpectedResult' (Resultado esperado) y luego despues de un ENTER final que el cursor vaya a la linea de arrange para poder empezar a escribir nuestro codigo.

Un snippet es solo un archivo XML que tiene una estructura especifica, lo puedes crear en cualquier editor de texto, en este caso yo usare el Visual Studio Code .

Asi que abrimos cualquier Folder en VS Code:


y aƱadimos un nuevo archivo XML:


Friday, July 7, 2017

Make your own C# snippet to stub out Unit Tests

The point of snippets is to avoid repetitive typing and if you are currently creating unit tests, aren't you tired of writing arrange,act and assert ?

If you are like me, then the answer is Yes. And not only that but there are other areas that we can use to improve our coding experience. So take this as an introductory example to snippets, and lets create our unit test one.

What we wan to achieve is that after a couple of keystrokes we get this:


And the focus on the WhatAreAreTesting part of the function name so we can change it then one TAB press for ExpectedResult and then a final ENTER to get us to the arrange line so we can start coding.

A code snippet is just an XML file with an especific structure, you can create it in any text editor you want, in this case I will use Visual Sutio Code .

So lets open any Folder on VS Code:


then Add a new XML File: