Grails中的测试服务产生';org.junit.ComparisonFailure:应为:<;一个[a]名字>;但事实是:<;一个[o]名字>';错误
我正在努力完成“Grails in Action”,在尝试为我的一项服务编写集成测试时遇到了一个问题 我意识到我使用的是Grails2.0.3,而这本书是在考虑Grails1.x.x的情况下编写的 这是我的服务:Grails中的测试服务产生';org.junit.ComparisonFailure:应为:<;一个[a]名字>;但事实是:<;一个[o]名字>';错误,grails,service,integration-testing,Grails,Service,Integration Testing,我正在努力完成“Grails in Action”,在尝试为我的一项服务编写集成测试时遇到了一个问题 我意识到我使用的是Grails2.0.3,而这本书是在考虑Grails1.x.x的情况下编写的 这是我的服务: package qotd 类报价服务{ boolean transactional = true def getRandomQuote(){ def allQuotes = Quote.list() def randomQuote if(allQuote
package qotd
类报价服务{
boolean transactional = true
def getRandomQuote(){
def allQuotes = Quote.list()
def randomQuote
if(allQuotes.size() > 0){
def randomIndex = new Random().nextInt(allQuotes.size())
randomQuote = allQuotes[randomIndex]
}
else{
randomQuote = getStaticQuote()
}
return randomQuote
}
def getStaticQuote(){
return new Quote(author: "Anonymous",
content: "Real Programmers Don't eat quiche")
}
}
下面是我的集成测试,位于“/Test/Integration/qotd/”中
package qotd
导入静态org.junit.Assert*
导入org.junit*
类QuoteServiceIntegrationTests扩展了GroovyTestCase{
def quoteService
@Before
void setUp() {
}
@After
void tearDown() {
}
@Test
void testStaticQuote() {
def staticQuote = quoteService.getStaticQuote()
assertNotNull quoteService
assertEquals "Ananymous",staticQuote.author
assertEquals "Real Programmers Don't Eat Quiche",staticQuote.content
}
}
为了以防万一,下面是我正在测试上述内容的Quote类:
包装qotd
课堂报价{
String content
String author
Date created = new Date()
static constraints = {
author(blank:false)
content(maxSize:1000,blank:false)
}
}
当我运行测试时,使用“测试应用程序-集成”我得到以下结果:
正在运行1集成测试。。。第1页,共1页
失败:testStaticQuote(qotd.QuoteServiceIntegrationTests)
org.junit.ComparisonFailure:expected:An[a]同名但was:An[o]同名
位于org.junit.Assert.assertEquals(Assert.java:125)
位于org.junit.Assert.assertEquals(Assert.java:147)
在qotd.QuoteServiceIntegrationTests.testStaticQuote(QuoteServiceIntegrationTests.groovy:24)中
如有任何见解,将不胜感激。谢谢大家! 您在这行中拼写“匿名”不正确
assertEquals“Anonymous”,staticQuote.author
您完全正确,我认为这是一个错误!谢谢:)