So i was little short on time lately, but know i have tried the
MethodInterceptor approach:
public class TestNG_MethodInterceptor extends StartTests implements
IMethodInterceptor {
private HashMap<String,String[]> removedmeths = new
HashMap<String,String[]>();
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> arg0,
ITestContext arg1) {
List<IMethodInstance> result = new ArrayList<IMethodInstance>();
if(skipit != null && skipit.size()>=1)
{
for(IMethodInstance mi:arg0)
{
String methodname = mi.getMethod().getMethodName();
String[] dependmeth =
build_clear_methodsname(mi.getMethod().getMethodsDependedUpon());
Boolean add = true;
for(String s:skipit)
{
if(s.equals(methodname))
{
removedmeths.put(methodname, dependmeth);
add = false;
}
}
for(String s :dependmeth)
{
if(removedmeths.containsKey(s))
{
/*
* Something like "mi.set_depend_on_Method(removedmeths.get(s));
* Setting the depend_on_Method of the actual test to the
depend_on_Methods of the removed test
*/
}
}
if(add)result.add(mi);
}
}
return result;
}
private String[] build_clear_methodsname(String[] input)
{
String[] methnames = new String[input.length];
for(int i=0;i<input.length;i++)
{
methnames[i] = input[i].split("\\.")[input[i].split("\
\.").length-1];
}
return methnames;
}
}
My Problem is, that i dont know how to change the Annoation of an
Method inside of the MethodInterceptor. I want to change the
dependencies for a Method. How can i do this?
Thanks for your replies!
On 24 Mai, 10:18, Benjamin87 <
b.soeltenf...@googlemail.com> wrote:
> Yeah, disabled is the right definition.
>
> What would happen to the depend Methods, if i remove an Method A with the
> IMethodInterceptor and Method B depends on Method A. Method B would be
> skipped or throw an error, right?
>
> In that Case the parameter variant would be the best way. But how can i pass
> Parameters from the .xml Configuration File to an Annotation Transformer
> Class to modify Annotation before the Suite starts?
>
> The @parameters is a Annotation as well, so it would be read after the
> Annotation Transformer?
>
>
>
>
>
>
>
>
>
> Cedric Beust wrote:
>
> > Annotation transformers are run before the annotations are read, by
> > definition (it wouldn't make much sense otherwise).
>
> > Another approach would be to define an IMethodInterceptor and remove from
> > that list the methods you don't want to run.
>
> > One last thing: "skipped" has a specific meaning in TestNG, you seem to
> > mean "disabled" or "ignored" here.
>
> > --
> > Cédric
>
> > On Wed, May 23, 2012 at 4:50 AM, Benjamin87
> > <
b.soeltenf...@googlemail.com>wrote:
>
> >> Hi,
>
> >> I want to achieve the following szenario:
>
> >> In the @BeforeSuite I want to define an Array with Testcases that should
> >> be
> >> skipped:
>
> >> skipit = new ArrayList<String>();
> >> skipit.add("Test1");
>
> >> So if the TestSuite starts, all Testcases that should be skipped and
> >> therefore are defined in theskiparray, should be set to "Enabled=false"
> >> in
> >> the Annotation. Also all Testcases, which depend on the skipped testcases
> >> should depend on thetestcasebefore the skiped one.