FizzBuzzTest.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class FizzBuzzTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class FizzBuzzTest
  12. {
  13. FizzBuzz test = new FizzBuzz();
  14. /**
  15. * Default constructor for test class FizzBuzzTest
  16. */
  17. public FizzBuzzTest()
  18. {
  19. }
  20. @Test
  21. public void fizzbuzzTest1(){
  22. //Give
  23. int x = 2;
  24. //When
  25. String actual = test.fizzbuzz(x);
  26. String expected = "2";
  27. //Result
  28. assertEquals(actual,expected);
  29. }
  30. @Test
  31. public void fizzbuzzTest2(){
  32. //Give
  33. int x = 3;
  34. //When
  35. String actual = test.fizzbuzz(x);
  36. String expected = "Fizz";
  37. //Result
  38. assertEquals(actual,expected);
  39. }
  40. @Test
  41. public void fizzbuzzTest3(){
  42. //Give
  43. int x = 5;
  44. //When
  45. String actual = test.fizzbuzz(x);
  46. String expected = "Buzz";
  47. //Result
  48. assertEquals(actual,expected);
  49. }
  50. /**
  51. * Sets up the test fixture.
  52. *
  53. * Called before every test case method.
  54. */
  55. @Before
  56. public void setUp()
  57. {
  58. }
  59. @Test
  60. public void fizzbuzzTest4(){
  61. //Give
  62. int x = 15;
  63. //When
  64. String actual = test.fizzbuzz(x);
  65. String expected = "FizzBuzz";
  66. //Result
  67. assertEquals(actual,expected);
  68. }
  69. /**
  70. * Tears down the test fixture.
  71. *
  72. * Called after every test case method.
  73. */
  74. @After
  75. public void tearDown()
  76. {
  77. }
  78. }