bala
2015-02-10 20:33:37 UTC
Having introduced Cucumber-JVM over many other tools recently and albeit a
lot of negative criticism it is taking shape. There are never ending
comparisons which I am trying to fulfill through front-end processing.
So here I am trying to set a dynamic filename for Cucumber json output for
various reasons but it proves to be tricky.
Reasons:
1. Cucumber json output doesn't have execution timestamp (I would love to
have environment, build number etc)
2. Clients want to know how often the so called Cucumber tests are run,
when and the trend (I use Javascript MVC to process the json and the
charts).
3. The only way I can provide it, is by naming json file with timestamp so
that it can be used to extract date/time info.
My customizations are as below:
@RunWith(RunCucumber.class)
@CucumberOptions(dryRun = false, plugin = {"pretty",
"json:target/cucumber.json"})
public class RunCucumber extends Cucumber {
static {
final CucumberOptions old = (CucumberOptions)
RunCucumber.class.getAnnotations()[0];
System.out.println("Original file=" + old.plugin()[1]);
Annotation newAnnotation = new CucumberOptions() {
....
@Override
public String[] plugin() {
String f =
"json:target/new-"+System.currentTimeMillis()+".json";
return new String[]{"pretty", f};
}
@Override
public Class<? extends Annotation> annotationType() {
return old.annotationType();
}
....
Field field = null;
try {
field = Class.class.getDeclaredField("annotations");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
field.setAccessible(true);
Map<Class<? extends Annotation>, Annotation> annotations = null;
try {
annotations = (Map<Class<? extends Annotation>, Annotation>)
field.get(RunCucumber.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
annotations.put(CucumberOptions.class, newAnnotation);
}
public RunCucumber(Class clazz) throws InitializationError, IOException
{
super(clazz);
}
@Test
public void meth(){
}
}
And from Maven
mvn clean verify -Dtest=RunCucumber
The problem is that I get intermittent
initializationError(RunCucumber) (RunCucumber.java:29) which points to
final CucumberOptions old = (CucumberOptions)
RunCucumber.class.getAnnotations()[0];
but if I put an System.out.println("customized cucumber running"); inside
meth(), it is working fine. I am totally confused as to what this sout has
got to do with initialization issue.
I would love to get some directions.
Thanks
Bala
lot of negative criticism it is taking shape. There are never ending
comparisons which I am trying to fulfill through front-end processing.
So here I am trying to set a dynamic filename for Cucumber json output for
various reasons but it proves to be tricky.
Reasons:
1. Cucumber json output doesn't have execution timestamp (I would love to
have environment, build number etc)
2. Clients want to know how often the so called Cucumber tests are run,
when and the trend (I use Javascript MVC to process the json and the
charts).
3. The only way I can provide it, is by naming json file with timestamp so
that it can be used to extract date/time info.
My customizations are as below:
@RunWith(RunCucumber.class)
@CucumberOptions(dryRun = false, plugin = {"pretty",
"json:target/cucumber.json"})
public class RunCucumber extends Cucumber {
static {
final CucumberOptions old = (CucumberOptions)
RunCucumber.class.getAnnotations()[0];
System.out.println("Original file=" + old.plugin()[1]);
Annotation newAnnotation = new CucumberOptions() {
....
@Override
public String[] plugin() {
String f =
"json:target/new-"+System.currentTimeMillis()+".json";
return new String[]{"pretty", f};
}
@Override
public Class<? extends Annotation> annotationType() {
return old.annotationType();
}
....
Field field = null;
try {
field = Class.class.getDeclaredField("annotations");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
field.setAccessible(true);
Map<Class<? extends Annotation>, Annotation> annotations = null;
try {
annotations = (Map<Class<? extends Annotation>, Annotation>)
field.get(RunCucumber.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
annotations.put(CucumberOptions.class, newAnnotation);
}
public RunCucumber(Class clazz) throws InitializationError, IOException
{
super(clazz);
}
@Test
public void meth(){
}
}
And from Maven
mvn clean verify -Dtest=RunCucumber
The problem is that I get intermittent
initializationError(RunCucumber) (RunCucumber.java:29) which points to
final CucumberOptions old = (CucumberOptions)
RunCucumber.class.getAnnotations()[0];
but if I put an System.out.println("customized cucumber running"); inside
meth(), it is working fine. I am totally confused as to what this sout has
got to do with initialization issue.
I would love to get some directions.
Thanks
Bala
--
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.
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.