Test driven development Radim Göth Outline •Extreme programming •What is TDD and how it is practiced •Unit testing •Installing NUnit •Coding katas Test pyramid http://watirmelon.files.wordpress.com/2012/01/idealautomatedtestingpyramid.png https://martinfowler.com/bliki/TestPyramid.html https://martinfowler.com/bliki/images/testPyramid/test-pyramid.png Unit vs integration testing 8 12 UnitA UnitB https://lh3.googleusercontent.com/GEXX6VCb39lo0hDgesXqsr8XZkhErlxeoedxefFhRhOFMaVBWAqbxug9yc-8gdFsL E6YENo6TKcvBlIRL5sbiR-eY2o0ZY9r1dl_SrQuNICI2dSbCi5yx621IbfWv7yvcXshHSM J. Ráček, Analýza a návrh systémů https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Extreme_Programming.svg/240px-Extreme_Pro gramming.svg.png Extreme Programming •Stand ups •Planning game •Pair programming •TDD •Collective code ownership •Continuous integration •Code is everythink •No useless analysis •No useless documentation Naming conventions •Project naming •.Tests • •Class naming •Tests • •Test method naming •Given_When_Then •_Given_Then • • Unit test structure •Arrange •Act •Assert • •One Assert per test (ideal situation) •More assert per test •Could be refactored (e.g. custom assert method) •Only if it doesn’t make sense to divide test into several others TDD •Kent Beck – reinvented TDD, invented XP •Software development process •Pair programming •Rules: •Write failing test •Write simplest implementation to pass the test •Refactor your code •Repeat • https://manojjaggavarapu.files.wordpress.com/2012/07/redgreenrefacor.png Image result for karate Coding katas •Is a way to •exercise your brain •exercise TDD •learn new language Leap year excercise •Write a function that returns true or false depending on whether its input integer is a leap year or not. • •A leap year is divisible by 4, but is not otherwise divisible by 100 unless it is also divisible by 400. • •2001 is a typical common year •1996 is a typical leap year •1900 is an atypical common year •2000 is an atypical leap year Fizz buzz •Fizz Buzz is a mathematical game which is played with a group of people. Each person says a number in sequence, but when the number is a multiple of 3, they have to say "Fizz", when it is a multiple of 5 they have to say "Buzz", and if it is a multiple of both 3 and 5, "FizzBuzz". If someone makes a mistake and it is noticed, they are out. • •A typical game might start like: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, etc. • •string FizzBuzz(int start, int count) Events •http://codingdojo.cz/ •http://globalday.coderetreat.org/ •