Mocking Objects Vs In-memory databases

144 views
Skip to first unread message

Suhas Walanjoo

unread,
Aug 14, 2015, 11:19:38 PM8/14/15
to growing-object-o...@googlegroups.com

Hi,

On my project we are using Spring framework with JUnit and Mockito, so calls to external systems are mocked. My current requirement is to manipuate the input text from UI (remove special characters etc.) before it gets stored in the database. I do know how it can be achieved using Spring application context along with an in-memory database like H2 or HSQL db, Hibernate or JDBC.

But I am wondering how  I can  assert that the massaged text got saved to a database table when I am using a mocking framework to mock calls to a database.

Thanks in advance!

Regards,

Suhaas

Matteo Vaccari

unread,
Aug 15, 2015, 4:24:15 AM8/15/15
to growing-object-o...@googlegroups.com
Hi Suhaas,

it seems to me that can do two different things: you can test the /intention/ to write things into a repository by testing your scenario with a mock repository.  And you can test-drive the implementation of your repository by using a real database.  For the latter, you will probably have to annotate your tests with @RunWith(SpringJUnit4ClassRunner.class).

Both activities are useful.  It's good when you separate your functional logic (how a message is massaged) from your non-functional logic (making persistence work.) and test-drive the two separately.

Matteo




--

---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriente...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Suhas Walanjoo

unread,
Aug 15, 2015, 8:38:43 PM8/15/15
to growing-object-o...@googlegroups.com

Thanks, Matteo

Reply all
Reply to author
Forward
0 new messages