TestNG 显示 0 测试运行 [英] TestNG shows 0 Test run

查看:52
本文介绍了TestNG 显示 0 测试运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 testNG 执行我的测试脚本并尝试以下代码,但在控制台中显示 0 表示运行、失败和跳过.因此,我无法验证脚本中的结果.

I'm trying to execute my test scripts using testNG and trying the below code, but 0 displayed against run, fail and skip in the console. Because of that I'm unable to verify the results in my script.

Java:

package com.demoaut.newtours.testcases;
import org.testng.Assert;
import org.testng.annotations.Test;

//import junit.framework.Assert;
public class TC002_CheckAssert {
    @Test
    public TC002_CheckAssert() {
        System.out.println("ajkcbh");
        try {
            Assert.assertEquals("Pass", "Pass");
        }
        catch(Exception e) {
            System.out.println("Exception:" + e.getLocalizedMessage());
        }
    }
}

我正在通过 testng.xml 文件执行上述脚本.

I am executing the above script through testng.xml file.

<suite name="Suite">
  <test name="Test">
   <classes>
      <class name="com.demoaut.newtours.testcases.TC002_CheckAssert" />
   </classes>
  </test>
</suite>

控制台结果:

ajkcbh

"==============================================="
Suite
Total tests run: 0, Failures: 0, Skips: 0
"==============================================="

推荐答案

您的代码块中有一个小错误.当您使用 TestNG 并在 @Test 注释中编写方法时,我们应该定义具有适当返回类型的方法.我使用了您自己的代码,并简单地将 返回类型 添加为 void,如下所示:

There is a minor bug in your code block. When you are using TestNG and writing methods within @Test annotation, we should define the methods with proper return types. I have used your own code and simply added the return type as void as follows:

import org.testng.Assert;
import org.testng.annotations.Test;

public class Q45191867_Assert_Pass_Suite 
{

    @Test   
    public void TC002_CheckAssert() 
    {
        System.out.println("ajkcbh");
        try
        {
            Assert.assertEquals("Pass", "Pass");
        }
        catch(Exception e)
        {
            System.out.println("Exception:"+e.getLocalizedMessage());
        }
    }
}

当作为TestNG Test执行时,代码块成功执行.

The code block executes successfully when executed as TestNG Test.

我已经使用以下 testng.xml 执行了转换为 TestNG 的代码块,如下所示:

I have executed the code block converting into TestNG with the following testng.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="demo.Q45191867_Assert_Pass_Suite"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

我以 TestNG Suite 的身份再次执行了这个代码块.在这种情况下,控制台上的输出也是:

I have executed this code block again as TestNG Suite. In this case as well the output on the console was:

[TestNG] Running:
  C:UsersAtechM_03LearnAutmationLearnAutomationTestNG	estng.xml

ajkcbh

===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

这篇关于TestNG 显示 0 测试运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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