TNG / junit-dataprovider

A TestNG like dataprovider runner for JUnit with many additional features
Apache License 2.0
246 stars 164 forks source link

Provide some utility methods #21

Closed aaschmid closed 10 years ago

aaschmid commented 10 years ago
aaschmid commented 10 years ago

Also think about providing some possibilities to work with Description of tests. Mainly parse description, and provide class name, test method name, test method arguments ... Current use case: JGiven of @janschaefer Edit: implemented in JGiven -> nothing to do in junit-dataprovider

aaschmid commented 10 years ago

@michaeladler can you tell me if that is what you wanted? Do you maybe have an idea for a better naming for the methods?

michaeladler commented 10 years ago

Yes, this goes in the right direction. Maybe two additional convenience methods:

public static <T> Object[][] toObjectArray( T... input ) {}

public static <T> Object[][] toObjectArray( Iterable<T> input ) {}

Then, instead of

$$($("foo"), $("bar"))

you can write

toObjectArray("foo", "bar")
michaeladler commented 10 years ago

I quite like the method name "$" since it is very short and thus makes it easy to read the code (since it is used very often). The method $$ is generally used only once so you could just call it "merge" - it merges the given Object[] arrays.

aaschmid commented 10 years ago

Ok, good points :-) I have just seen that method public static Object[][] testForEach(Object... args) is what you want with toObjectArray("foo", "bar"), isn't it? And I like $$ for object arrays as it is like $ for objects, however merge is a good name either. I will think about it ...

michaeladler commented 10 years ago

Oh, now I understand... I actually considered this test code that you would remove in the final version :-) You are right, that's what I was looking for. Maybe you should just drop the prefix "test".

aaschmid commented 10 years ago

Yes, you may be right, I have also thought about that. Shouldn't we than change the name of the class to something more meaningful like DataProviders (as guava does for its helpers) or Tests? I don't know because most of the time you will statically import these methods, wouldn't you?

michaeladler commented 10 years ago

Personally I prefer to import all static methods so that I don't have to prefix the class ;-) In that case calling the method "forEach" is probably too general. How about "toSingletonProvider" or something like that. I know, it's hard to find a good name.

aaschmid commented 10 years ago

Yes, it indeed is ... that's why I ask ...

aaschmid commented 10 years ago

@michaeladler If you want, you can review the changes and if they are ok, I will merge it into master branch. I have kept the naming for now, hope that's OK, although I also like toSingletonProvider (but not as much as testForEach)