Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:11:50+00:00 2026-06-06T23:11:50+00:00

In my integration test I do the following: void testSave() { def controller =

  • 0

In my integration test I do the following:

void testSave() {
    def controller = new BookController()
    controller.params.title = "Awesome Book"
    controller.params.pages = 1000
    controller.save()
    // i want to check book data here
}

How can I retrieve the Book my controller persisted and check that the title == "Awesome Book" and that pages == 1000? Can I somehow access the bookInstance variable in my controller from the test?

I cannot assume that Book.get(1) will give me the correct Book because there will be bootstrap data in the database. The controller redirects to a completely Book unrelated page so I cannot get the id from the URL. The only thing I can think of is to do something like this:

void testSave() {
    def oldIdList = Book.list()*.id
    // set up the parameters and call controller.save()
    def insertedId = Book.list()*.id - oldIdList
    // check Book.get(insertedId) properties
}

but I’m hoping there is a better way…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:11:51+00:00Added an answer on June 6, 2026 at 11:11 pm

    Assuming you are using Grails 2.0.x you can look up the book by any of its properties using the findBy* methods:

    def book = Book.findByTitle("Awesome Book")
    assertNotNull book
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is pseudo code of an integration test that is failing: [Test] void
Consider the following code: [Test] public void WidgetTest() { foreach (Widget widget in widgets)
Let's look at the following piece of code which I unintentionally wrote: void test
What is the best way to unit test/integration test the following : @Service(fooService) public
I get the following error when running any NUnit integration test - Assembly setup
How to test the following code with integration rspec test (I'm also using capybara)
Please, help me understand the following. I have an spring integration test, which I'm
I'm trying to test the following helper method in rails: def current_has_class_link(text, path, class_name=selected)
As part of a Selenium integration test, I wrote the two following lines in
i've got an integration test that grabs some json result from a 3rd party

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.