Lazy Data Providers

7 views
Skip to first unread message

Cédric Beust ♔

unread,
Oct 12, 2005, 6:48:18 PM10/12/05
to testn...@googlegroups.com, Eugene Kuleshov, Elliotte Harold
By popular demand, I added lazy Data Providers to TestNG.  It was actually fairly simple.  Your Data Provider can now return an Iterable<Object[]>:

@DataProvider(name = "test1")
public Iterable<Object[]> createTestData() { ... }

TestNG will then iterate through the Object[] this iterable returns and will invoke the corresponding test methods with the returned row of parameters.  The main advantage is that the parameter rows are now created one by one, on demand, instead of being all created upfront.  This makes Data Driven Testing (not to be confused with Test Driven Development :-)) much more useful.

Of course, you can still return Object[][] if you want to.

Thanks to Eugene and Elliotte for convincing me that this was an important feature.

This new feature will go into TestNG 4.1 (which I will probably push very soon).

If you want to see the gory details, I attached the test I created for this new feature.  I simulated lazy creation by exposing the counter on my iterator, so I can keep track of how far the iterator has gone, which I test in verifyNames() on top of the values that are being passed.

Feedback welcome.

--
Cédric


IterableTest.java
MyIterator.java

Cédric Beust ♔

unread,
Oct 12, 2005, 7:51:24 PM10/12/05
to testn...@googlegroups.com, Eugene Kuleshov, Elliotte Harold
Quick update:  Hani pointed out that this wouldn't work for JDK 1.4 users, so I am thinking of changing Iterable<Object[]> to Iterator.

More backward compatible and easier to code for users anyway (and trivial for me to fix).

--
Cedric
--
Cédric

Justin Lee

unread,
Nov 9, 2005, 12:07:37 AM11/9/05
to testn...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Attached is patch I'm wanting to commit. I get the error every once in
a while about not being able to find a constructor. In most cases it
can find it just fine, but any exception encountered generates that
message. It's misleading and wrong in many cases. This patch creates a
more useful and informative. Any objections? The actual text I'm not
terribly married to. But attaching that message at the end is essential
in my mind.

- --
Justin Lee
http://www.antwerkz.com
AIM : evan chooly
720.299.0101
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDcYQZ8pJ9e9iJHOsRA/yAAKDjRCWIHl+smTssJWILlfs/943X3QCfchse
9vBXbCgo2MUlZpv/nOZOczE=
=/ViM
-----END PGP SIGNATURE-----
error_log.patch

Alexandru Popescu

unread,
Nov 9, 2005, 4:20:24 AM11/9/05
to testn...@googlegroups.com
#: Justin Lee changed the world a bit at a time by saying on 11/9/2005 7:07 AM :#
It looks like you are trying to attach a not null message from the original exception or the wrapped
cause message. It makes sense to me, so go on and commit it :-).

./alex
--
.w( the_mindstorm )p.

Justin Lee

unread,
Nov 9, 2005, 8:49:31 AM11/9/05
to testn...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

That's exactly it! That's checked in now.

Alexandru Popescu wrote:

> It looks like you are trying to attach a not null message from the
> original exception or the wrapped cause message. It makes sense to me,
> so go on and commit it :-).

> ./alex
> --
> .w( the_mindstorm )p.

- --
Justin Lee
http://www.antwerkz.com
AIM : evan chooly
720.299.0101
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDcf5r8pJ9e9iJHOsRA76UAKDeMzsn1Yn+W+Rr8NpDGv1Hj/X1ygCgrX67
/5OA6sUBFQjkL+p9habjN+Q=
=kGWu
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages