lunes, 13 de octubre de 2014

NCrunch, your friend with TDD

Today I wanted to talk you about NCrunch, a great tool I´ve discovered thanks to my colleages in my new job. It allows us to automatically run our Unit Tests while we are writing the production code.


So we´ve been told about TDD, Test Driven Development. The methodology itself is easy to understand but specially in the beginning hard to take, I think is because it may seem like against common sense. TDD is based on three simple steps:
1) Start with a failing test (don´t fail to fail!). This test checks a small working piece of functionality.
2) We write the minimun amount of code that makes it pass. Minimun is minimun!
3) Refactor the code (tests and production code) to avoid duplicated code and do improvements.
We iterate though every of these steps, adding more and more tests until we have all of the user story finished. Previous tests must pass in every moment.

You´ve probably noticed that a quite important part is running tests. I´m so used to watch the tests explorer (whatever it is) and run tests manually as I follow TDD.

So here it comes NCrunch to give us a hand in this task. NCrunch is running on paralel, watching our changes, and running all of the tests again as soon as it finds any modification.
We´ll see a few things going on:


There´s a circle in the corner of the right side. It will be green if every tests pass. Otherwise it goes red with a number, this tells the number of failing tests or projects that don´t compile.

In the left side along the code, we see some arrows. These are starting tests. The arrow is green if it passes or red if the test breaks.
In addition we can find code coverage in a very easy graphical fashion. If you see, we have some circles in colour. This circles are green if that line of code is succesfully reached by a test, likewise it goes red if the test doesn´t pass. Circle becomes black when the line is not covered at all.

If you browse the NCrunch page you can see a video of all of this in action. An image is worth a thousand words:
http://www.ncrunch.net/

You can imagine how this helps doing TDD: we write a test and it goes red inmediately. We implement the minimun code (Resharper can help us doing that from the test). It will be the minimun, otherwise we´ll see black circles appearing in the logic. Test goes green and we do refactor having the test still green, together with other previous tests.

It´s just amazing how you forget about Tests Explorer. When I started in my new job I noticed my colleagues hardly ever debug the code, and the reason for that was easy: NCrunch was doing the hard work for them. They code simply focusing on the programming part.

NCrunch can be used with MSpec, Specflow, MSTests, NUnit and probably many others.
NCrunch is just another productivy tool (yes, Resharper is the big boy). I know I have a few friends that don´t like to polute their wonderful Visual Studio environment, arguing mainly because it makes VS slower.
Well, while the former is true, I´m a big fan of these tools, and the reason for that is because I can just simply a more efficient programmer. Yes, the machine can go slower, but isn´t productivity increasing a good reason to ask for more memory to your manager?:)

As a side note, I would like to talk you something very funny that happened to me regarding NCrunch. In order to get the position I got in my new company, I need to do a programming exercise. I finished it and I was proud of the result. I followed TDD and so, my code coverage ought to be great. A couple of days after I started the new job, I opened my exercise solution with my brand new Visual Studio and NCrunch installed. Suddenly I noticed an entire method full of black circles, that wasn´t covered at all... Luckily my technical leader, Richard, was so kind to let me start working with them.

Cheers mates, keep coding!


32 comentarios:

  1. Thankyou for sharing this code, its will be very helpful for us, luxury villas in Gurgaon

    ResponderEliminar
  2. Employee Transportation Process Optimization Agiledge offers a unique service in optimizing transport processes. Our team of Six Sigma Black Belts are domain experts in the area of employee transportation. Our unique process consulting and optimization approach enables us to work with organizations to Understand Cost incurred for transport across facilities. Analyze controls across different sub processes. employee transport management

    ResponderEliminar
  3. Thankyou for sharing this code, its will be very helpful for us, i have also some useful information about scheme, affordable housing scheme .

    ResponderEliminar
  4. Fantastic Four, a contemporary re-imagining of Marvel’s original and longest-running superhero team, centers on four young outsiders who teleport to an alternate and dangerous universe, which alters their physical form in shocking ways. Their lives irrevocably upended, the team must learn to harness their daunting new abilities and work together to save Earth from a former friend turned enemy.

    Watch Avengers 2 Online Free

    Watch Insurgent Online Free

    Watch Avengers 2 Online Free

    Watch Avengers 2 Online Free

    Watch Furious 7 Online Free

    Watch Game of Thrones Season 5 Online Full Episodes

    Watch Game of Thrones Season 5 Full Streaming Online Free

    Manny Pacquiao vs Floyd Mayweather Live Stream

    ResponderEliminar
  5. Floyd 'Money' Mayweather is already the richest sportsman in the world. Now the American is set to earn another $200m (£130m) for this weekend's world welterweight title fight.

    Manny Pacquiao vs Floyd Mayweather Live Stream

    Manny Pacquiao vs Floyd Mayweather Live Stream

    ResponderEliminar
  6. The Bella's are back, and they are better than ever. After being humiliated infront of none other than the President of the United States of America, the Bella's are taken out of the Aca-Circuit.

    Watch Pitch Perfect 2 Online Free

    ResponderEliminar
  7. Visitors at the Jurassic World theme park run for their lives when the genetically engineered Indominus Rex and other dinosaurs go on a rampage.

    Watch Jurassic World (2015) Online Free

    ResponderEliminar
  8. Game of Thrones, the famous American show is all set to hit the television screens in the month of May. The warmth and the shocking incidents of it’s previous episodes are still flying in the mind of the viewers but Game of Thrones season 6 - See more at: http://thegameofthronesseason6stream.com/#sthash.wuss4itE.dpuf

    Game of Thrones Season 6 Online
    oscar nominations 2016

    ResponderEliminar



  9. The Walking Dead Season 6 Episode 14,15&16




    The Walking Dead Season 6 Finale




    Batman v Superman: Dawn of Justice Full Movie




    Game of Thrones Season 6 Online




    Watch Game of Thrones Season 6 Episode 1 Online




    Dead Pool Full Movie



    News For Mobile





    ame Of Thrones season 5 Episode 4 plot|summary The fourth episode of the fifth season of HBOs television series Game of Thrones i.e. “Sons of the Harpy” aired on May3,2015 and was written by Dave Hill and directed by Mark Mylod. The episode revealed that Cersei Lannister meets with the High Sparrow authorizing the Faith Militant’s revival which caused one of the Petyr Baelish’s brothels and Ser Loras Tyrell is arrested due to his homosexuality. Stannis Baratheon told his daughter, Shireen the story of how she got afflicted with greyscale and how he did everything in his control to cure her. Sansa lighted candle for her deceased family members.



















    The Walking Dead Season 6 Episode 14,15&16




    The Walking Dead Season 6 Finale




    Batman v Superman: Dawn of Justice Full Movie




    Game of Thrones Season 6 Online




    Watch Game of Thrones Season 6 Episode 1 Online




    Dead Pool Full Movie



    News For Mobile





    ResponderEliminar

  10. Batman v Superman: Dawn of Justice Full Movie Online



    Batman v Superman: Dawn of Justice Full Movie



    HBO Game of Thrones Season 6 Episode 1




    HBO Game of Thrones Season 6 Episode 1 Online



    Man of Steel has a lot of shortcomings, but one thing it has going for it is a very solid arc, and a real through-line, that actually pays off.

    What few people seem to get about Man of Steel is, it’s actually a very optimistic movie. Here’s what happens: Kal-El is sent to Earth, the survivor of a doomed planet, and is raised by the Kents, who fear what’ll happen to him if other people find out he’s an alien. So they urge him to keep his powers secret, and Pa Kent even sacrifices his life to deter Clark from using his powers publicly. Years later, some more aliens show up, and they’re evil as all fuck. Superman is forced to emerge from hiding to fight them.

    So the first time anybody finds out about Superman is not when he saves a plane from crashing, but when he gets caught up in a giant scrape with other members of his own species. This scenario stacks the deck massively against anybody ever accepting, let alone welcoming, Superman. But because Superman shows so much concern for human life, and is clearly fighting to protect Earth from his own kind, he wins people over.

    ResponderEliminar