I have the following spock integration test for in grails 2.4.3, I have searched on google but didn't find anything understandable
@Mock([Product,Price])
class ProductViewerSpec extends IntegrationSpec {
ProductController productController = new ProductController()
void "Test the complete flow of retrieving and viewing a product"() {
when: "The loadProducts method is executed to get list of products"
String barCode = "1"
String description = "testProduct"
Set<Price> prices = new HashSet<Price>()
Product product = new Product(barCode, description, prices)
Price price1 = new Price(10 as BigDecimal).save(flush: true, failOnError: true)
product.prices.add(price1)
Price price2 = new Price(12 as BigDecimal).save(flush: true, failOnError: true)
product.prices.add(price2)
Price price3 = new Price(14 as BigDecimal).save(flush: true, failOnError: true)
product.prices.add(price3)
Price price4 = new Price(11 as BigDecimal).save(flush: true, failOnError: true)
product.prices.add(price4)
Price price5 = new Price(12 as BigDecimal).save(flush: true, failOnError: true)
product.prices.add(price5)
product.save(flush: true, failOnError: true)
productController.productService.setPrices(product)
List<Product> productList = productController.productService.loadProducts(product.getBarCode(), null)
then: "All prices calculated and returned correctly"
Product.count() == 1
productList.size() == 1
productList.get(0).barCode == barCode
productList.get(0).description == description
productList.get(0).prices.size() == 5
productList.get(0).getAveragePrice() == 11.8 as BigDecimal
productList.get(0).getLowestPrice() == 10 as BigDecimal
productList.get(0).getHighestPrice() == 14 as BigDecimal
productList.get(0).getIdealPrice() == 14.4 as BigDecimal
productList.get(0).prices.id.contains(price1.id)
productList.get(0).prices.id.contains(price2.id)
productList.get(0).prices.id.contains(price3.id)
productList.get(0).prices.id.contains(price4.id)
productList.get(0).prices.id.contains(price5.id)
}
}
I am getting following error when I run grails test-app from command line.
| Compiling 1 source files
| Compiling 1 source files.
| Running 5 integration tests...
| Running 5 integration tests... 1 of 5
| Failure: com.prizypricer.core.ProductViewerSpec
| java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)
| Failure: com.prizypricer.core.ProductLoaderSpec
| java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)
| Completed 1 integration test, 0 failed in 0m 0s
Can anyone tell what is wrong?
Aucun commentaire:
Enregistrer un commentaire