Getting “java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException”Exception

后端 未结 4 2080
梦谈多话
梦谈多话 2021-01-13 12:46

I wanted to invoke testng programmatically. Not eclipse plug-in.

I have associated \"testng-6.8.21.jar\" and running through eclipse and i ran below code:

         


        
4条回答
  •  盖世英雄少女心
    2021-01-13 13:30

    Change:

    Class cls = Class.forName("TestSuite.TestCases.AddContactHappyPath").getClass();
    test.setTestClasses(new Class[] { cls });
    

    By:

     test.setTestClasses(new Class[] { AddContactHappyPath.class });
    

    All code is

    import org.testng.TestNG;
    import com.xxx.test.others.AddContactHappyPath;
    
    public class SampCls {
        public static void main(String[] args) throws ClassNotFoundException {
            TestNG test = new TestNG();
             test.setTestClasses(new Class[] { AddContactHappyPath.class });
             test.run();
        }
    }
    

    TestNG code is:

    import org.testng.annotations.*;
    
    public class AddContactHappyPath {
    
        @Test()
        public void AddContactHappyPathTest() {
            System.out.println("hello world");
        }
    }
    

    Console result:

    [TestNG] Running:
      Command line suite
    
    hello world
    
    ===============================================
    Command line suite
    Total tests run: 1, Failures: 0, Skips: 0
    ===============================================
    

提交回复
热议问题