Comments (3)
- Yes, Grails 2.3 now defaults to creating Spock tests
- I'll need to look into this. I could be the test method name or something else.
BTW, you will also need to remove the Spock plugin from the dependencies in grails-app/conf/BuildConfig.groovy
if you are using Grails 2.3. Spock is included in Grails itself now.
from graina2.
Thank you again for the quick feedback, Peter. I think I managed to dig a solution from the internet.
Instead of using assertEquals
, I used expect:
and and:
, and it seems to work fine now. Meaning, now if I run grails test-app QuoteServiceSpec
, in the command prompt I get | Completed 1 unit test, 0 failed in 0m 1s
. Note that earlier I was getting | Completed 0 unit test, 0 failed in 0m 1s
. I also verified by opening /qotd/target/test-reports/html/index.html in a web browser and it says "A single test executed without a single error or failure!".
I am including my modified QuoteServiceSpec.groovy
class for reference. Note the only changes made in the testStaticQuoteReturnsQuicheQuote
method, and everything else the same.
package qotd import grails.test.mixin.TestFor import spock.lang.Specification /** * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions */ @TestFor(QuoteService) class QuoteServiceSpec extends Specification { def setup() { } def cleanup() { } void "test something"() { } void testStaticQuoteReturnsQuicheQuote(){ Quote staticQuote = service.getStaticQuote() //assertEquals("Anonymous", staticQuote.author) //assertEquals("Real Programmers Don't eat quiche", //staticQuote.content) expect: staticQuote.author == "Anonymous" and: staticQuote.content == "Real Programmers Don't eat quiche" } }
Sorry, I am not experienced enough yet to explain why "assertEquals" does not work and "expect:" works, but here are a few reference I Googled that were helpful ...
http://stackoverflow.com/questions/18999343/how-do-you-test-service-or-controller-methods-in-grails-2-3
https://code.google.com/p/spock/wiki/SpockBasics
http://jira.grails.org/browse/GRAILS-10538
Also, on a side note to "BTW, you will also need to remove the Spock plugin from the dependencies in grails-app/conf/BuildConfig.groovy
if you are using Grails 2.3. Spock is included in Grails itself now.". In my case the BuildConfig.groovy
was automatically generated by Grails and the Spoke plugin was not included to start with (therefore I did not have to remove the plugin). Thank you!
from graina2.
Chapter has now been updated to use Spock tests, with a mention that Grails 2.2 and earlier automatically create JUnit tests.
from graina2.
Related Issues (20)
- Scaffolding does not correctly handle multipart forms
- In section 1.3.2 either add an explicit return or explain why it's optional
- Ch 8 (p.219) references non-existent section in ch 2
- Including `password` constraint on `ApplicationUser` doesn't work
- Section 3.2.1 Page 69 Reference to integration test not found HOT 2
- Section 3.4.2, page 85, keeping the many side sorted, paragraph 2, last line HOT 1
- Chapter 3, page 90, figure 3.10, public.user table HOT 1
- Redundant unscoped isEditState variable used in listing 13.10, 13.11
- Chapter 6, Page 145, paragraph 2, line 2 HOT 2
- Chapter 6, Page 146, Figure 6.4 HOT 1
- Page 159 first sentence HOT 2
- Hubbub can't run with 2.4.4 HOT 1
- Technique for executing single feature method doesn't work
- Suggestion for reader changes to listing 8.5 is confusing
- Page 218, Listing 8.11 HOT 1
- Page 223, first paragraph under code fragment HOT 1
- Page 223, Prototype or jQuery? HOT 1
- Chapter 9, Page 240, first line, "When you give..." HOT 2
- Chapter 9, listing 9.9 HOT 2
- `random` action should not be a closure property
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graina2.