File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Can genRocket also help in Unit Testing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Can genRocket also help in Unit Testing?" Watch "Can genRocket also help in Unit Testing?" New topic
Author

Can genRocket also help in Unit Testing?

Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
Hi Gregg and Hycel,

Welcome to Coderanch. Ok, first of all, sorry if this is a stupid question.

I am a software developer and I frequently need to write test cases for the features I have developed. For setting up data in database tables, we generally use XML files that are fed to a suite and the suite runs appropriate database manager classes' methods that insert those records in the database tables.

The challenge for me is not so much to generate millions of records. What I require is an easy way to set up test data ( say less than 50 records ) in multiple tables with dependencies before I run my tests and an easy way to delete that data after my tests have run.

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? Can I sort of program it to set the same data every time I run my tests ( so I can write my validation logic )? 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.

Also can it be integrated with Test Suites like TestNG?

Note : I don't know much about TestNg or other testing frameworks or tools. I have only worked on JUnit till now. But I need to find out about other tools that are out there.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1760
    
    7

http://www.coderanch.com/t/630668/Testing/GenRocket-automated-test-integration



Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 560
    
    7

Greetings Gregg - nice to see your name again.

I don't want to side track this thread, but genRocket can also do the more tricky stress and performance tests also correct? (that is what I gleamed from the website but wanted to make sure).

thanks,

-steve
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Hey Steve,

The sort answer is, yes! I'd love to elaborate. Maybe you could start a new thread and expound on your question a bit?
Heena Agarwal
Ranch Hand

Joined: Dec 25, 2013
Posts: 261
    
    4
Wow, this is interesting. Actually I was(am) not aware if there are other tools also out there that have made data setup for feature testing easy. In my old projects we didn't have the need to setup a lot of data in the database tables, so this was never a requirement. But in my current project we require a lot of data setup to be done in database tables and we don't have any setup that is already available for feature testing.

We have developed unit tests using TestNg and we are exploring Mockito for stubbing and mocking. We have just started exploring the various tools that are out there for helping us with data setup required for feature testing.

It is nice to be able to let an external tool like GenRocket take care of setting up data in db tables than to have us spend a lot of effort in designing and writing many lines of code just for the data setup for testing. Also our automation team has just developed a framework for CI using bamboo. So if we all start developing tests for our features in such a way that they can also be used by the CI tool, I think it'll be a nice thing. Not sure what my organization will go with, but genRocket is definitely what I can speak to my seniors about ( I know the true power of genRocket would be realized by people who run advanced tests like performance or stress tests but it's good to know that it can help us with feature testing also ).

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
.

Thanks for the correction. Sorry, I meant feature testing only as you probably might have guessed. And thanks for demonstrating how I can use it with my methods annotated with @BeforeTest annotation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can genRocket also help in Unit Testing?