Run time dependency throws an error as "which is not annotated with @Test or not included"

2,046 views
Skip to first unread message

arjunmalli veepuru

unread,
May 23, 2016, 2:13:00 AM5/23/16
to testng-users
Hi All,

I have two methods in a class ex: method1() and method2(). When I give method2 depends on method1 it is throwing an error "method2() is depending on method public void method1() throws java.io.IOException,java.lang.InterruptedException, which is not annotated with @Test or not included."

Can you please share an idea to fix this issue?

Thanks in Advance!

Regards,
Arjun.

⇜Krishnan Mahadevan⇝

unread,
May 23, 2016, 2:55:55 AM5/23/16
to testng...@googlegroups.com
Arjun,

What does your code look like ? Can you please share that ?
Also tell us how are you executing your tests. 



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/

--
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 testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

arjunmalli veepuru

unread,
May 25, 2016, 7:55:41 AM5/25/16
to testng...@googlegroups.com
Hi Krishnan Mahadevan, 
      Here you can check my scenario. I have a class like 
public class Hello{

        @Test
         public void A(){
         }

        @Test(dependsonmethods="A")
        public void B(){
        }

}

Here I am calling the above mentioned two methods from testNG programatically like

Class Suite{

  TestNG tng = new TestNG();
  tng.addListener(rtest);
XmlSuite suite = new XmlSuite();
ArrayList<XmlTest> tests = new ArrayList<XmlTest>();
suite.setName("Hello");
List<XmlTest> xmlTest = new ArrayList<XmlTest>(); XmlTest test = new XmlTest(suite);
String methods []= {A, B};
for(int i=0; i <2; i++){
test.setName(methods[i]);
ArrayList<XmlInclude> methodsToRun = new ArrayList<XmlInclude>(); ArrayList<XmlClass> classes1 = new ArrayList<XmlClass>(); XmlClass classes = new XmlClass();
     classes.setName("Hello");
     methodsToRun.add(new XmlInclude(methods[i]));
     classes.setIncludedMethods(methodsToRun);
     classes1.add(classes);
     test.setXmlClasses(classes1);
     xmlTest.add(test);
     tests.addAll(xmlTest);
}
suite.setTests(tests);
xmlSuites.add(suite);
tng.setXmlSuites(xmlSuites);
tng.run();

}

When I run Suite I getting an error as "B() is depending on method A() throws java.io.IOException,java.lang.InterruptedException, which is not annotated with @Test or not included."

Can you see this code and share your answer?

Thanks!

Regards,
Arjun.


--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/f-_jFwbqY24/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
May 25, 2016, 11:42:32 PM5/25/16
to testng...@googlegroups.com
I have fixed the issues in your code. The below should do the trick

public class TestNGViaCode {
public static void main(String[] args) {

TestNG tng = new TestNG();
        XmlSuite suite = new XmlSuite();
        ArrayList<XmlTest> tests = new ArrayList<>();
suite.setName("Hello");
List<XmlTest> xmlTest = new ArrayList<>();

XmlTest test = new XmlTest(suite);
String methods[] = {"A", "B"};
        XmlClass classes = new XmlClass();
        ArrayList<XmlInclude> methodsToRun = new ArrayList<>();
for (int i = 0; i < 2; i++) {
test.setName(methods[i]);
//For inner classes we would need to use "$" to refer to them instead of using "."
String name = TestNGViaCode.class.getCanonicalName() + "$" + MyTestClass.class.getSimpleName();
classes.setName(name);

methodsToRun.add(new XmlInclude(methods[i]));
}
classes.setIncludedMethods(methodsToRun);
        test.setXmlClasses(Arrays.asList(classes));
xmlTest.add(test);
tests.addAll(xmlTest);
suite.setTests(tests);
List<XmlSuite> xmlSuites = new ArrayList<>();
xmlSuites.add(suite);
tng.setXmlSuites(xmlSuites);
tng.run();

}

public static class MyTestClass {
@Test
public void A() {
System.err.println("A()");
}

@Test (dependsOnMethods = "A")
public void B() {
System.err.println("B()");
}
}
}

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/

Reply all
Reply to author
Forward
0 new messages