Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list with different elements #31

Closed
wagnerfrancisco opened this issue Jun 28, 2013 · 8 comments
Closed

list with different elements #31

wagnerfrancisco opened this issue Jun 28, 2013 · 8 comments

Comments

@wagnerfrancisco
Copy link

Just started using this framework and I didn't realize how to create a list with different elements. I think this is not possible, right? Something like this:

add("items", has(2).of(Item.class, "itemOne", "itemTwo");

@douglasrodrigo
Copy link
Member

You also can add literal values, like this:

add("items", Arrays.asList("itemOne", "itemTwo"));

@nykolaslima
Copy link
Member

@douglasrodrigo I think that @wagnerfrancisco didn't mean this.

When we use has().of() we can only pass one template, I believe he wants to specify more than one template.

@wagnerfrancisco am I correct?

@wagnerfrancisco
Copy link
Author

It's exactly that @nykolaslima ! Is it possible?

@nykolaslima
Copy link
Member

It's not possible.

But why you wanna do this?

If you wanna do this because you need different data, you can use functions to generate custom data.

Eg: add("email", regex("my regex to generate emails");
add("creationDate", instant("2 days ago");
add("age", random(17, 30, 45));

Using functions instead of "hard-coded" data maybe help you. This way you dont need to use two different tremplates and instead of this you can create a template that cover the 2 other templates.

Sent from my iPhone

On 28/06/2013, at 21:40, Wagner Francisco Mezaroba notifications@github.com wrote:

It's exactly that @nykolaslima ! Is it possible?


Reply to this email directly or view it on GitHub.

@wagnerfrancisco
Copy link
Author

Hi. Actually I'm testing an xml conversion, I'm creating an object that is going to be converted to xml. This object contains a list and I just would like to ensure this list is going to be properly converted.

I already had this object created without fixture-factory and now I'm justing refactoring the code. But thinking better, I really think in my case it's not necessary to have two different values in the list. Even if the objects are equal my test is going to be useful. I was just trying to get the same object I had before using fixture-factory.

Thanks!

@nykolaslima
Copy link
Member

But you can have different objects using the same template. To do this you need to use functions instead of hard coded values.

Just like my examples in the other comment.

Sent from my iPhone

On 28/06/2013, at 23:29, Wagner Francisco Mezaroba notifications@github.com wrote:

Hi. Actually I'm testing an xml conversion, I'm creating an object that is going to be converted to xml. This object contains a list and I just would like to ensure this list is going to be properly converted.

I already had this object created without fixture-factory and now I'm justing refactoring the code. But thinking better, I really think in my case it's not necessary to have two different values in the list. Even if the objects are equal my test is going to be useful. I was just trying to get the same object I had before using fixture-factory.

Thanks!


Reply to this email directly or view it on GitHub.

@nykolaslima
Copy link
Member

@wagnerfrancisco can we close this?

@wagnerfrancisco
Copy link
Author

@nykolaslima and @douglasrodrigo, thanks for your help.

Yes, feel free to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants