SCJP, SCJD, SCWCD, SCBCD, SCEA
SCJP 5, SCWCD 5
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
David Newton wrote:Same way as anything else--insert some data, read it back to make sure it's there (or has changed, or whatever else). That's more of an integration test, though, rather than a unit test, since an external system is involved.
Prabhakar Reddy Bokka wrote:Junit tests are bit different from the manual unit test / integration test.
Your Junit test cases should run standalone without depending on server / database for proividing consistent results.
You just need to test your business logic in your class. So you can mock the outside world.
We have many mock frameworks for this purpose like jmock, easymock, mockrunner etc.,
In your case you need to mock the database with a mock framework. you can use DbUnit framework for this purpose. DbUnit is a mock framework to mock database.
DbUnit
Jeanne Boyarsky wrote:Prabhakar,
That would be for unit tests. JUnit is also used for integration tests which do involve the database/server.
Jiafan,
How does the real front end/client app connect to the server? Remote call? Your JUnit test would do the same thing.
SCJP, SCJD, SCWCD, SCBCD, SCEA
Jiafan Zhou wrote:I am now thinking of creating a new database on the client side (identical to the database on the server) and after that, I can write JUnit tests directly towards the CRUD *in the client JVM*. What do you think of this?
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:
Jiafan Zhou wrote:I am now thinking of creating a new database on the client side (identical to the database on the server) and after that, I can write JUnit tests directly towards the CRUD *in the client JVM*. What do you think of this?
How does that test the database access code? It is on the server, no?
SCJP, SCJD, SCWCD, SCBCD, SCEA
Jiafan Zhou wrote:The database access code is intended to deploy on the server JVM, but I think it is also possible to run the same code on the client machine as long as I set up the database correctly. So that the database access code can be tested on the client JVM.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2