Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nBuilder alternative for Java

Is there any tool like nBuilder for java?

I want to build objects for unit testing and I dont want to have one builder class for each entity in my domain.

I am currently using mockito but it doesnt replace the functionality of nBuilder.

like image 916
Pomber Avatar asked Jan 27 '11 21:01

Pomber


3 Answers

You can try DataFactory: Generate test data with DataFactory

Also I found this poject at google code that could be helpful: Random Data Generator

They are not equivalent to nBuilder, but they try to provide similar functionality to the one provided by nBuilder. It's not a perfect replacement but is the closer I could find.

Hope this helps.

like image 129
Diego Avatar answered Oct 30 '22 01:10

Diego


TestNG has @DataProvider and @Factory.

like image 32
Rostislav Matl Avatar answered Oct 30 '22 02:10

Rostislav Matl


While not strictly matching what you want with nBuilder, I'd strongly recommend looking into the Spock testing framework. It has very strong mocking and stubbing tools built into it, and one of the greatest perks of Spock is Data Driven testing.

http://docs.spockframework.org/en/latest/data_driven_testing.html

I find data driven testing to be some of the most efficient unit testing I've come across, to date. I don't know if this will directly replace the kinds of things nBuilder can do, but I can tell you that my unit testing is much more thorough (and easier to write) with Spock.

like image 2
Jason Lowenthal Avatar answered Oct 30 '22 01:10

Jason Lowenthal