Contenu connexe Similaire à Grails unit testing (20) Grails unit testing14. Need 'split personality': when you start testing, become paranoid and malicious. Surprisingly hard to do: people don't like finding out that they make mistakes. 17. Good Testing has high probability of finding as-yet-undiscovered errors 24. A unit is the smallest testable part of an application. 25. Each test case is independent from the others: substitutes like method stubs, mock objects, can be used to assist testing a module in isolation. 26. A unit test provides a strict, written contract that the piece of code must satisfy. 27. It tests individual methods or blocks of code without considering for surrounding infrastructure. 28. It is integral part of the development, so developers write unit test cases. 31. It is highly reliant on Refactoring and Programmer skills 34. Unit testing allows the programmer to refactor code at a later date, and make sure the module still works correctly 36. Unit testing may reduce uncertainty in the units themselves and can be used in a bottom-up testing style approach.By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier. 40. When software is developed using a test-driven approach, the unit test may take the place of formal design. Each unit test can be seen as a design element specifying classes, methods, and observable behaviour. 44. What makes it stand out from the crowd is its beautiful and highly expressive specification language 60. where block always comes last in a method expect: Math.max(a, b) == c where: [a,b,c] << [[1,2,2],[3,7,7]] 62. def "testing exception is not thrown"() { when: //something that does'nt throw an exception then: notThrown(NullPointerException) } 84. All of your dynamic finders (findBy* and findAllBy* ) 85. get(), getAll(), exists(), count(), list(), create(), save(), validate(), delete(), discard(), addTo(), removeFrom() 87. countBy(), createCriteria(), executeQuery(), executeUpdate(), find(), findAll(), findAllWhere(), findWhere(), ident(), listOrderBy(), merge(), withCriteria(), withTransaction() 118. Test Def “test my simple action ”() { Setup: mockDomain(BankFile, [new BankFile(id: 1)]) BankFileService serviceMock = Mock() serviceMock.commit(params) >> new BankFile(id: 1) } controller.bankFileService = serviceMock when: mockParams.id = 1 controller.commit() then: redirectArgs.action==”show” redirectArgs.id==1 } Notes de l'éditeur . . . . . .