Я работаю через «Grails in Action», и у меня возникает проблема при попытке написать интеграцию тест для одного из моих сервисов.Служба тестирования в Grails производит «org.junit.ComparisonFailure: ожидается: <An[a]nymous> но был: <An[o]nymous>» error
Я понимаю, что я использую Grails 2.0.3, тогда как книга была написана с учетом Grails 1.x.x.
Вот моя служба:
package qotd
класс QuoteService {
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")
}
}
А ниже мой тест интеграции, расположенный в '/ тест/интеграции/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, который я тестирую выше:
package qotd
класса Quote {
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: ожидается: [a] nymous, но был: [o] nymous
в org.junit.Assert.assertEquals (Assert.java:125)
на org.junit.Assert.assertEquals (Assert.java:147)
на qotd.QuoteServiceIntegrationTests.testStaticQuote (QuoteServiceIntegrationTests.groovy: 24)
Любое понимание будет оценено по достоинству. Спасибо вам всем!
Вы совершенно правильно, и вот я подумал, что это была ошибка! Спасибо :) –