Pass runtime parameters to testng listeners

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass runtime parameters to testng listeners

Iana Bondarska
Hi, 
could you please help me with testng listeners. I have test method annotated with dataprovider and I need to skip this test method based on value from dataProvider. 
E.g. 
I have method

@Test(dataProvider="sources")
public void test1(String name){
}

@DataProvider
public static Object[][]sources(){
return new Object[]{new Object[]{"value1","value2"}};
}

I want test1 test to skip for "value1".
 
I've checked various ITestNGListener intefaces : IAnnotationTransformer,ITestInterceptor -- seems  that they do not know anything about runtime parameters passed to method, only static info.
Is there any way to implement such conditional test execution?

Best Regards, 
Iana

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pass runtime parameters to testng listeners

Cédric Beust ♔-2

Why don’t you throw a SkipException in your test based on the value you receive?


-- 
Cédric


On Thu, Feb 11, 2016 at 9:26 PM, Iana Bondarska <[hidden email]> wrote:
Hi, 
could you please help me with testng listeners. I have test method annotated with dataprovider and I need to skip this test method based on value from dataProvider. 
E.g. 
I have method

@Test(dataProvider="sources")
public void test1(String name){
}

@DataProvider
public static Object[][]sources(){
return new Object[]{new Object[]{"value1","value2"}};
}

I want test1 test to skip for "value1".
 
I've checked various ITestNGListener intefaces : IAnnotationTransformer,ITestInterceptor -- seems  that they do not know anything about runtime parameters passed to method, only static info.
Is there any way to implement such conditional test execution?

Best Regards, 
Iana

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pass runtime parameters to testng listeners

Iana Bondarska
that's exactly what I do for now.  I just wondered if there is neater way to check such preconditions , e.g. set "enabled" false for Test annotation.
I found InvokedMethodListener and was able to check preconditions in this method. 

пʼятниця, 12 лютого 2016 р. 01:22:36 UTC+2 користувач Cédric Beust ♔ написав:

Why don’t you throw a SkipException in your test based on the value you receive?


-- 
Cédric


On Thu, Feb 11, 2016 at 9:26 PM, Iana Bondarska <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="JGFLzo5wAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">yana...@...> wrote:
Hi, 
could you please help me with testng listeners. I have test method annotated with dataprovider and I need to skip this test method based on value from dataProvider. 
E.g. 
I have method

@Test(dataProvider="sources")
public void test1(String name){
}

@DataProvider
public static Object[][]sources(){
return new Object[]{new Object[]{"value1","value2"}};
}

I want test1 test to skip for "value1".
 
I've checked various ITestNGListener intefaces : IAnnotationTransformer,ITestInterceptor -- seems  that they do not know anything about runtime parameters passed to method, only static info.
Is there any way to implement such conditional test execution?

Best Regards, 
Iana

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="JGFLzo5wAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="JGFLzo5wAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pass runtime parameters to testng listeners

Krishnan Mahadevan
Iana,

Would something like below be what you are looking for ?

@Listeners(FunWithListeners.SimpleEavesdropper.class)
public class FunWithListeners {
@Test(dataProvider = "dp")
public void testMethod(TestData data) {
System.err.println("Another data came in with its value as " + data.getData());
}

@DataProvider(name = "dp")
public Object[][] getData() {
return new Object[][] {
{new TestData("Hello")},
{new TestData(null)}
};
}

public static class SimpleEavesdropper implements IInvokedMethodListener {

@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
Object[] parameters = method.getTestResult().getParameters();
if (null == parameters || parameters.length != 1) {
return;
}
Object parameter =parameters[0];
if (! (parameter instanceof SkipTest)) {
return;
}
SkipTest skip = ((SkipTest) parameter);
if (skip.skip()) {
throw new SkipException("Null (or) Empty values needn't be dealt with.");
}
}

@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {

}
}

public static class TestData implements SkipTest {
private String data;
public TestData(String data) {
this.data = data;
}

public String getData() {
return data;
}

@Override
public boolean skip() {
return (null == data || data.trim().isEmpty());
}
}

public interface SkipTest {
boolean skip();
}
}


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Fri, Feb 12, 2016 at 1:50 PM, Iana Bondarska <[hidden email]> wrote:
that's exactly what I do for now.  I just wondered if there is neater way to check such preconditions , e.g. set "enabled" false for Test annotation.
I found InvokedMethodListener and was able to check preconditions in this method. 

пʼятниця, 12 лютого 2016 р. 01:22:36 UTC+2 користувач Cédric Beust ♔ написав:

Why don’t you throw a SkipException in your test based on the value you receive?


-- 
Cédric


On Thu, Feb 11, 2016 at 9:26 PM, Iana Bondarska <[hidden email]> wrote:
Hi, 
could you please help me with testng listeners. I have test method annotated with dataprovider and I need to skip this test method based on value from dataProvider. 
E.g. 
I have method

@Test(dataProvider="sources")
public void test1(String name){
}

@DataProvider
public static Object[][]sources(){
return new Object[]{new Object[]{"value1","value2"}};
}

I want test1 test to skip for "value1".
 
I've checked various ITestNGListener intefaces : IAnnotationTransformer,ITestInterceptor -- seems  that they do not know anything about runtime parameters passed to method, only static info.
Is there any way to implement such conditional test execution?

Best Regards, 
Iana

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.