How to convert data table into custom java obeject?

60 views
Skip to first unread message

G.L.

unread,
Oct 17, 2016, 5:01:07 AM10/17/16
to Cukes
Hi I'm trying to convert the data table in feature file into custom java object, should I use @XStreamConverter, can anyone give an example to create custom XStreamConvert class?

e.g.

//in feature file:

Given MyClassData with

| name        | Date           | dataTypeCode  |

| myName | 2016-07-01  |  code1               |


//in step.java file:

@Given("^MyClassData with$")

public void MyClassData _With(List<MyClass> MyClassDataInput) throws Throwable {

dataList = MyClassDataInput;

}



Public MyClass{

String name;

Date date;

MyTypeCode typeCode;

}



public MyTypeCode{

public static code1= new MyTypeCode("code1");

public static code2 = new MyTypeCode("code2");

public static code3= new MyTypeCode("code3");

}



How to map dataTypeCode  into MyTypeCode class when loading feature file? Thanks for help!


Andrew Premdas

unread,
Oct 17, 2016, 5:51:15 AM10/17/16
to cu...@googlegroups.com
Hopefully someone else will provide the technical solution you require

I'd just like to point out that writing scenarios this way is very counter productive. Because you are including so much detail about how something is done in your scenario you are creating a great deal of development debt via duplication. Whenever something changes in how you do this particular task, not only will you have to change the implementation, you will also have to change 'every' scenario that relies on your implementation.

What tends to happen is that sometime after scenarios like this are written, someone will implement a small change and suddenly lots of scenarios will fail, Understanding why the scenarios have failed ends up taking much much longer, than implementing the change. This undermines the value of the entire set of features. It is very easy to get into a downward spiral here.

A better way to write scenarios is to 'push the how down' (as Matt Wynne would say). Here all the details of how something is done go down your testing stack. Your test stack is

scenarios
step definitions
step definition helper methods
your code

The further down the stack you push the how the less maintenance issues you will when change is made.

There really is no place for data in scenarios.

Anyhow hope thats useful, and perhaps can suggest a different/better way of using Cucumber

All best

Andrew

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Thomas Sundberg

unread,
Oct 17, 2016, 7:31:39 AM10/17/16
to cu...@googlegroups.com
Hi!

I wrote a blog post a while back about it, maybe it can help you.
http://www.thinkcode.se/blog/2014/06/30/cucumber-data-tables

HTH
Thomas
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://www.thinkcode.se/blog
Twitter: @thomassundberg

Better software through faster feedback
Reply all
Reply to author
Forward
0 new messages