I am trying to execute my test scripts using testNG and trying below code but 0 displayed against run, fail and skip in console...because of that i am unable to verify results in my script
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());
}
}
}
I am executing above script through testng.xml file
<suite name="Suite">
<test name="Test">
<classes>
<class name="com.demoaut.newtours.testcases.TC002_CheckAssert" />
</classes>
</test>
</suite>
Console resule
ajkcbh
"==============================================="
Suite
Total tests run: 0, Failures: 0, Skips: 0
"==============================================="
Here is the Answer to your Question:
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 properreturn types
. I have used your own code and simply added the return type as void as follows:The code block executes successfully when executed as
TestNG Test
.I have executed the code block converting into
TestNG
with the followingtestng.xml
as follows:I have executed this code block again as
TestNG Suite
. In this case as well the output on the console was:Let me know if this Answers your Question.