Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tdd

583 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Tdd

  1. 1. Тесты — хорошо :) Когда писать тесты?Сколько писать тестов?
  2. 2. 1.You may not write production code until you have written a failing unit test.2.You may not write more of a unit test than is sufficient to fail, and not compiling is failing.3.You may not write more production code than is sufficient to pass the currently failing test. Три закона TDD «Clean Code», Robert C.Martin
  3. 3. Prime Factors Kata Object Mentor, Inc. www.objectmentor.com blog.objectmentor.comfitnesse.org www.junit.org Copyright © 2005 by Object Mentor, Inc All copies must retain this page unchanged.
  4. 4. 1package primeFactors;import junit.framework.TestCase;public class PrimeFactorsTest extends TestCase { public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); }}
  5. 5. 1package primeFactors;import junit.framework.TestCase;import java.util.List;public class PrimeFactorsTest extends TestCase { public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } private List<Integer> list() { return null; }}
  6. 6. 1package primeFactors; package primeFactors;import junit.framework.TestCase; public class PrimeFactors { }import java.util.List;public class PrimeFactorsTest extends TestCase { public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } private List<Integer> list() { return null; }}
  7. 7. 1package primeFactors; package primeFactors;import junit.framework.TestCase; import java.util.*;import java.util.List; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); public void testOne() throws Exception { } assertEquals(list(),PrimeFactors.generate(1)); } } private List<Integer> list() { return null; }}
  8. 8. 1package primeFactors; package primeFactors;import junit.framework.TestCase; import java.util.*;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); public void testOne() throws Exception { } assertEquals(list(),PrimeFactors.generate(1)); } } private List<Integer> list() { return new ArrayList<Integer>(); }}
  9. 9. 1package primeFactors; package primeFactors;import junit.framework.TestCase; import java.util.*;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); private List<Integer> list() { } return new ArrayList<Integer>(); } } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); }}
  10. 10. 1 2package primeFactors; package primeFactors;import junit.framework.TestCase; import java.util.*;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); private List<Integer> list() { } return new ArrayList<Integer>(); } } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),PrimeFactors.generate(2)); }}
  11. 11. 1 2package primeFactors; package primeFactors;import junit.framework.TestCase; import java.util.*;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { return new ArrayList<Integer>(); private List<Integer> list(int... ints) { varargs } List<Integer> list = new ArrayList<Integer>(); } for (int i : ints) list.add(i); return list; } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),PrimeFactors.generate(2)); }}
  12. 12. 1 2package primeFactors; package primeFactors;import junit.framework.TestCase; import java.util.*;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(2); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),PrimeFactors.generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),PrimeFactors.generate(2)); }}
  13. 13. 1 2package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*; import junit.framework.TestCase; import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(2); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); }}
  14. 14. 1 2 3package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(2); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); }}
  15. 15. 1 2 3package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(n); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); }}
  16. 16. 1 2 3 4package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); primes.add(n); for (int i : ints) } list.add(i); return primes; return list; } } } public void testOne() throws Exception { assertEquals(list(),generate(1)); } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); }}
  17. 17. 1 2 3 4package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); if (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); }}
  18. 18. 1 2 3 4 5package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); if (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); }}
  19. 19. 1 2 3 4 5 6package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); if (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); }}
  20. 20. 1 2 3 4 5 6package primeFactors; package primeFactors;import static primeFactors.PrimeFactors.generate; import java.util.*;import junit.framework.TestCase;import java.util.*; public class PrimeFactors { public static List<Integer> generate(int n) {public class PrimeFactorsTest extends TestCase { List<Integer> primes = new ArrayList<Integer>(); private List<Integer> list(int... ints) { if (n > 1) { List<Integer> list = new ArrayList<Integer>(); while (n%2 == 0) { for (int i : ints) primes.add(2); list.add(i); n /= 2; ! ! ! return list; } } if (n > 1) primes.add(n); public void testOne() throws Exception { } assertEquals(list(),generate(1)); return primes; } } } public void testTwo() throws Exception { assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); }}
  21. 21. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; if (n > 1) { } while (n%2 == 0) { primes.add(2); public void testOne() throws Exception { n /= 2; assertEquals(list(),generate(1)); } } if (n > 1) primes.add(n); public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); return primes; } } } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  22. 22. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; if (n > 1) { } int candidate = 2; while (n%candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } if (n > 1) public void testTwo() throws Exception { primes.add(n); assertEquals(list(2),generate(2)); } } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  23. 23. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; if (n > 1) { } int candidate = 2; while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } } public void testTwo() throws Exception { if (n > 1) assertEquals(list(2),generate(2)); primes.add(n); } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  24. 24. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } if (n > 1) { while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } } public void testTwo() throws Exception { if (n > 1) assertEquals(list(2),generate(2)); primes.add(n); } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  25. 25. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } if (n > 1) { while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } } public void testTwo() throws Exception { if (n > 1) assertEquals(list(2),generate(2)); primes.add(n); } return primes; } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  26. 26. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } while (n > 1) { while (n % candidate == 0) { ! ! ! public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } candidate++; public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); if (n > 1) } primes.add(n); return primes; public void testThree() throws Exception { assertEquals(list(3),generate(3)); } } } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  27. 27. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } while (n > 1) { while (n % candidate == 0) { public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); n /= candidate; } } candidate++; public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); return primes; } } } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  28. 28. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; int candidate = 2; } while (n > 1) { for (; n%candidate == 0; n/=candidate) public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); } candidate++; } public void testTwo() throws Exception { return primes; assertEquals(list(2),generate(2)); } } } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  29. 29. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; } for (int candidate = 2; n > 1; candidate++) for (; n%candidate == 0; n/=candidate) public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); } return primes; } public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { assertEquals(list(2,2),generate(4)); } public void testFive() throws Exception { assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}
  30. 30. 1 2 3 4 5 6 7package primeFactors;import static primeFactors.PrimeFactors.generate;import junit.framework.TestCase;import java.util.*; package primeFactors;public class PrimeFactorsTest extends TestCase { import java.util.*; private List<Integer> list(int... ints) { List<Integer> list = new ArrayList<Integer>(); public class PrimeFactors { for (int i : ints) public static List<Integer> generate(int n) { list.add(i); List<Integer> primes = new ArrayList<Integer>(); return list; } for (int candidate = 2; n > 1; candidate++) for (; n%candidate == 0; n/=candidate) public void testOne() throws Exception { primes.add(candidate); assertEquals(list(),generate(1)); } return primes; } public void testTwo() throws Exception { } assertEquals(list(2),generate(2)); } public void testThree() throws Exception { assertEquals(list(3),generate(3)); } public void testFour() throws Exception { } assertEquals(list(2,2),generate(4)); public void testFive() throws Exception { 3 строчки кода!!! assertEquals(list(2,3),generate(6)); } public void testSix() throws Exception { assertEquals(list(2,2,2),generate(8)); } public void testSeven() throws Exception { assertEquals(list(3,3),generate(9)); }}

×