取决于组方法不能从另一个类文件正确执行 [英] Depends On Groups Method is not executing prorperly from another class file

查看:89
本文介绍了取决于组方法不能从另一个类文件正确执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个单独的类文件. 在Vehicle.java文件中,有2个组Bike & Car,每个组具有3种不同的方法.

There are two separate class files. Inside Vehicle.java file there are 2 groups Bike & Car and each group is having 3 different methods.

请参阅下面的代码段.

public class Vehicle {

    @Test (groups = {"Car"})
    public void car1()
    {
        System.out.println("Message : Car 1 Method.");
    }

    @Test (groups = {"Bike"})
    public void bike1()
    {
        System.out.println("Message : Bike 1 Method.");
    }

    @Test (groups = {"Car"})
    public void car2()
    {
        System.out.println("Message : Car 2 Method.");
    }

    @Test (groups = {"Bike"})
    public void bike2()
    {
        System.out.println("Message : Bike 2 Method.");
    }

    @Test (groups = {"Car"})
    public void car3()
    {
        System.out.println("Message : Car 3 Method.");
    }

    @Test (groups = {"Bike"})
    public void bike3()
    {
        System.out.println("Message : Bike 3 Method.");
    }
}

另一个类文件是Dependent.java.在此文件中,我从Vehicle.java文件中调用了一个Bike组.

Another class file is Dependent.java. Inside this file I have called one group Bike from Vehicle.java file.

然后运行Dependent.java文件.该时间Car组也与Bike组一起执行. 但是在我的Dependent.java文件中,我没有调用Car组.

Then I run the Dependent.java file. That time Car group is also executing along with Bike group. But in my Dependent.java file I have not called Car group.

请参阅Dependent.java文件代码段.

public class Dependent {

    @Test(dependsOnMethods = {"openbrowser"})
    public void login()
    {
        System.out.println("Message : Login Method Called..");
    }

    @Test(dependsOnGroups = {"Bike"})
    public void setup()
    {
        System.out.println("Message : Setup Method Called..");
    }

    @Test(dependsOnMethods = {"setup"})
    public void openbrowser()
    {
        System.out.println("Message : Openbrowser Method Called..");
    }

    @Test(dependsOnMethods = {"login"})
    public void logout()
    {
        System.out.println("Message : After login Method Called..");
    }

}

编辑代码:- 这是我的testing.xml文件.

Edited Code :- Here is my testing.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite guice-stage="DEVELOPMENT" name="Demo TestNG">
 <test verbose="2" name="Cross Browser">

    <classes>
            <class name="com.abc.Dependent" />      
    </classes>

  </test> 
</suite>

有人可以告诉我该如何处理吗?

Can anybody tell me how to handle this case?

推荐答案

关闭并重新启动IDE,并使用以下.xml:

Close and restart your IDE and use following .xml:

 <suite name="Suite" verbose="1">
<test name="Test1">

    <groups>
        <run>

        <exclude name="Car" />
        </run>
    </groups>
    <classes>

        <class name="example.Dependent" />
        <class name="example.Vehicle" />


    </classes>

</test>


 </suite> 

这篇关于取决于组方法不能从另一个类文件正确执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆