11

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.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Pomber
  • 1,165
  • 2
  • 9
  • 13

5 Answers5

4

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.

Diego
  • 1,531
  • 1
  • 15
  • 27
  • Neither of the libraries are equivalent to nBuilder. – Mohayemin Jul 25 '12 at 06:00
  • @Mohayemin They are not equivalent, 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. – Diego Jul 25 '12 at 12:53
  • Yes, thats true. But U did not mention this in your answer. That is why I was misguided. Can you please edit your answer so that the same does not happen to someone else? Also, I can take away my downvote. – Mohayemin Jul 25 '12 at 17:23
  • @Mohayemin You are right, I will edit my answer. Thanks for pointed this :) – Diego Jul 26 '12 at 12:24
3

TestNG has @DataProvider and @Factory.

Rostislav Matl
  • 4,294
  • 4
  • 29
  • 53
  • I like your answer, but it's not nearly fully fleshed out. I'll look into `@Factory` and the TestNG framework more closely. – Makoto Nov 10 '13 at 18:08
2

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.

Jason Lowenthal
  • 790
  • 1
  • 5
  • 16
1

CodePro JUnit Test Case Generation

Ashish
  • 735
  • 1
  • 6
  • 15
1

I'm not familiar with nBuilder, but it looks to have some overlap with QuickBuilder - a project I put together that generates on the fly implementations of test data builders to interfaces you supply.

https://github.com/hcoles/QuickBuilder

It has some support for producing sequences of values, but does not generate values for you as nBuilder seems to.

Also, similar in functionality to QuickBuilder but presenting a different interface is, makeiteasy

https://code.google.com/p/make-it-easy/

henry
  • 5,923
  • 29
  • 46