Discussion:
[Cucumber] How to convert data table into custom java obeject?
G.L.
2016-10-14 14:16:13 UTC
Permalink
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!
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrew Premdas
2016-10-17 09:51:11 UTC
Permalink
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
Post by G.L.
Hi I'm trying to convert the data table in feature file into custom java
create custom XStreamConvert class?
e.g.
Given MyClassData with
| name | Date | dataTypeCode |
| myName | 2016-07-01 | code1 |
@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!
--
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
For more options, visit https://groups.google.com/d/optout.
--
------------------------
Andrew Premdas
blog.andrew.premdas.org
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thomas Sundberg
2016-10-17 11:31:16 UTC
Permalink
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
Post by G.L.
Hi I'm trying to convert the data table in feature file into custom java
custom XStreamConvert class?
e.g.
Given MyClassData with
| name | Date | dataTypeCode |
| myName | 2016-07-01 | code1 |
@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!
--
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
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
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...