Heena,
These are great questions. The Q&A Jelle linked to is useful, but incomplete for your question. Let me see if I can address some of them.
So can I have the @BeforeTest parts of my program invoke the test data creation part using GenRocket and @AfterTest parts invoke test data deletion part using GenRocket?
In your @BeforeTest method you can do as the link from Jelle eludes to:
You could even run multiple Scenarios, one right after the other
These Scenarios might populate a database, write out files to XML, or just whatever the chosen Receiver does. Each Scenario could even output to multiple formats and data sources.
As for the @AfterTest, we've found that this is still better managed a bit more thoughtfully. Simply destroying everything is not always the best solution. Most often, you'll want some residual data from test to test. Also, when you're tests complete fully, it should undo every change that was done. By nature and by default, most all Testing frameworks do this without asking. So we've chosen to not worry too much about it.
Can I sort of program it to set the same data every time I run my tests ( so I can write my validation logic )?
Absolutely! When you create a Scenario, you will decide what data is going to be generated. Patterned data is going to be your aim in these situations. For example, given a User domain, every time you run your tests you want the same 50 usernames. You would give User.id a
RangeGen:
You would then give User.username a
ConcatGen:
As you can see above, the ConcatGen uses a Reference to the ID so it can build the patterned data, which would result in the following usernames:
Every time you run the Scenario, that will be the output. And you can apply the same technique using many different Generators for all of your Attributes.
But we also understand that sometimes you just want Random data. Fortunately, GenRocket can still produce the same Random data every time. We do this by using a Seed. You can see an example of how this works in one of our blog posts:
http://www.genrocket.com/seeding-randomly-generated-data/
Can a tool like GenRocket help in unit testing? I mean it'll be a big help if I will not have to invoke my database manager classes. Sometimes the existing database manager classes do not have methods for a certain test requirement. And it is taxing to create such methods. So if an external tool that can be invoked by my Java program can do this, it's an awesome thing.
It is important to distinguish between the different types of tests. Unit tests should never invoke external systems like databases. All external service calls should be mocked in some way. Integration tests and Functional tests, on the other hand, do communicate with databases and external services.
That said, GenRocket will work for any kind of testing. If you need data in any shape or form, GenRocket can help. We have
Receivers that generate data to XML, CSV, JSON, SQL Files, directly to a database, and in a couple of days, we'll have available a WebService Receiver which will take generated data and post it to an end point.
I hope this helps. Let me know if I need to elaborate any further.