Your SlideShare is downloading. ×
  • Like
Testing in-groovy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Testing in-groovy

  • 576 views
Published

Groovy Unit Testing

Groovy Unit Testing

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
576
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Groovy Unit Testing By Franz See [email_address] http://twitter.com/franz_see
  • 2. Agenda I. Review Basics A. Parts B. Organization II. Groovy Test
  • 3. Review Basics :: Parts @RunWith(Suite.class) @Suite.SuiteClasses([..]) class GameBoardTests { static class Move_Validation extends GivenGameBoard { @Test( expected = IllegalMoveException.class ) void givenXIsBelow1() { } @Test( expected = IllegalMoveException.class ) void givenXIsAbove3() { } ... } static class Move_Marking extends GivenGameBoard { @Test void givenValidMove_shouldMarkLocation() { } @Test void givenValidMoves_shouldMarkLocations() { } } ... }
  • 4. Review Basics :: Parts @Test void givenValidMove_shouldMarkLocation() { int x = 1, y = 3 gameBoard.move(x, y) assertEquals "Should have been marked 'X' after the move.", X, gameBoard.getCells()[y-1][x-1] }
  • 5. Review Basics :: Parts @Test void givenValidMove_shouldMarkLocation() { int x = 1, y = 3 assertThat "[GUARD] Makes sure that it is not 'X' ' + 'before the move.", gameBoard.getCells()[y-1][x-1], not(equalTo(X)) gameBoard.move(x, y) assertEquals "Should have been marked 'X' after the move.", X, gameBoard.getCells()[y-1][x-1] }
  • 6. Review Basics :: Organization A. Test by Class B. Test by Feature C. Test by Fixture
  • 7. Review Basics :: Organization :: by Class @RunWith(Suite.class) class GameBoardTests { @Test( expected = IllegalMoveException.class ) void givenXIsBelow1_whenMove_then _thenComplain () {…} @Test( expected = IllegalMoveException.class ) void givenXIsAbove3_whenMove_thenComplain() {…} @Test void givenValidMove_whenMove_shouldMarkLocation() {…} @Test void givenValidMoves_ whennMove_ shouldMarkLocations() {…} }
  • 8. Review Basics :: Organization :: by Feature @RunWith(Suite.class) @Suite.SuiteClasses([..]) class GameBoardTests { static class Move { @Test( expected = IllegalMoveException.class ) void givenXIsBelow1_then_thenComplain() {…} @Test( expected = IllegalMoveException.class ) void givenXIsAbove3_thenComplain() {…} @Test void givenValidMove_shouldMarkLocation() {…} @Test void givenValidMoves_shouldMarkLocations() {…} } }
  • 9. Review Basics :: Organization :: by Fixture @RunWith(Suite.class) @Suite.SuiteClasses([..]) class GameBoardTests { static class GivenXIsBelow1 { @Test( expected = IllegalMoveException.class ) void thenComplain() {…} } static class GivenXIsAbove3 { @Test( expected = IllegalMoveException.class ) void thenComplain() {…} } static class GivenValidMove { @Test void shouldMarkLocation() {…} @Test void shouldMarkLocations() {…} } }
  • 10. Groovy Test (see code)
  • 11. Thank you. Questions?
  • 12. References
    • Xunit Test Patterns
    • 13. Working Effectively with Legacy Code
    • 14. http://www.mockobjects.com/
    • 15. http://tech.groups.yahoo.com/group/testdrivendevelopment/
    • 16. http://sites.google.com/site/tddproblems/
    • 17. http://code.google.com/p/tic-tac-toe-tdd/
    • 18. http://code.google.com/p/appfuse-top-to-bottom-tdd/