I'm performing a simple test, but the test fails because Service Bean can not be involved in the test class . Below is my test class
class QuoteServiceTests extends GrailsUnitTestCase {def zero testStaticQuote () {def staticQuote = quoteService.getStaticQuote () assertEquals ( "Messi", staticQuote.author) assertEquals (quoteService "Look at me today Man City ", against staticQuote.content)}}
can not be called getStaticQuote method to test the null object Java ()
error failed with the following .lang.NullPointerException:
Assume that you are using a version before 2 (and JUnit instead of Spock), then you must add the manual service:
< pre> class QuoteServiceTests extends GrailsUnitTestCase {def quotation service void setup () {quoteService = new quoteService ()} void testStaticQuote () {d ef staticQuote = quoteService.getStaticQuote () // ...
< / pre> or Grails uses 2 are after, then you need an annotation:
@ TestFor (QuoteService) // have 'service' category QuoteServiceTests { Zero testStaticQuote () {def st Lets call QuoteService through aticQuote = service.getStaticQuote () // ...
Comments
Post a Comment