Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit testing

Unit testing

Talk about Unit Testing: Pet / Cin / Universidade Federal de Pernambuco.
https://www.facebook.com/events/372202459624692/

Cloning and running tests on senna https://asciinema.org/a/14458

Henrique Vicente

December 05, 2014

Transcript

55 slides
  1. Why • Legacy code = code without tests • Safety

    net = fewer defects • Test cases = free and up-to-date docs • Prove that your code works • Ensure changes don’t break a thing
  2. Challenges • Lack of company culture • Legacy code •

    Code coverage • Experimenting • Dependencies • Data providers • Nondeterministic algorithms
  3. Unit tests • Independent from each other • Runs damn

    fast (ms to seconds) • Essential if you decide to use TDD • Don’t test private methods, cover it indirectly
  4. Data provider • Mock your data • Unit tests shouldn’t

    talk with SQL databases, remote procedures, and so on.
  5. Continuous Integration • Not to be confused with integration testing

    • Useful for integration testing • Let your developers know the status of your software builds
  6. Why are JUnit4 test cases with expected exceptions shown as

    not covered? http://www.eclemma.org/faq.html
  7. JUnit tests annotations • @Test • @Before • @After •

    @BeforeClass • @AfterClass • @Ignore
  8. JUnit asserts • void assertEquals(boolean expected, boolean actual) • void

    assertTrue(boolean expected, boolean actual) • void assertFalse(boolean condition) • void assertNotNull(Object object) • void assertNull(Object object) • void assertSame(boolean condition) • void assertNotSame(boolean condition) • void assertArrayEquals(expectedArray, resultArray);
  9. • pre-commit to abort commits without —no-verify • post-commit to

    give you an opportunity to —amend before pushing to a remote.
  10. • A Virtual Conference for Developers http://hacksummit.org/ • http://en.wikipedia.org/wiki/File:Wistar_rat.jpg •

    OMG PONIES!!! (AKA HUMANITY: EPIC FAIL)
 http://codeblog.jonskeet.uk/2009/11/02/omg-ponies-aka-humanity-epic-fail/ or Jon Skeet’s video at hack.summit • http://en.wikipedia.org/wiki/File:Test-driven_development.PNG • http://www.zyracuze.com/for-your-information/kiss-keep-it-simple-stupid/ • Watch Uncle Bob (Robert Martin) videos, read his Code Clean and Coder Clean books, and if you have to deal with legacy code, try Working Effectively with Legacy Code.

More Decks by Henrique Vicente

Other Decks in Programming