Thank you Cedric, here is my code,
Car.java
public class Car
{
private String make;
private String model;
private int year;
public Car(String make, String model, int year)
{
this.make = make;
this.model = model;
this.year = year;
}
public String toString()
{
return make + " " + model + " " + year;
}
}
CarTest.java
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class CarTest
{
@Test(groups = { "functest" })
public void testToStringPositive()
{
Car car = new Car("Honda", "Accord", 2010);
Assert.assertEquals(car.toString(), "Honda Accord 2010");
}
@Test(groups = { "functest" })
public void testToStringNegative()
{
Car car = new Car("Honda", "Accord", 2010);
Assert.assertFalse(car.toString().equals("Honda Accord 2011"));
}
@Test(dataProvider = "test-data")
public void testWithParameters(String make, String model, int year,
String expected, boolean result)
{
Car car = new Car(make, model, year);
if (result)
Assert.assertEquals(car.toString(), expected);
else
Assert.assertFalse(car.toString().equals(expected));
}
@DataProvider(name = "test-data" )
public Object[] [ ] rangeData( )
{
return new Object[ ] [ ] {
{ "Honda", "Accord", 2010, "Honda Accord 2010", true},
{ "Honda", "Accord", 2010, "Honda Accord 2110", true},
{ "Toyota", "Camry", 2010, "Toyota Camry 2010", true},
{ "Toyota", "Camry", 2010, "Toyota Camri 2010", true},
{ "BMW", "325", 2010, "BMW 325 2010", true},
};
}
}
Controller or Main class
import org.testng.TestNG;
import org.testng.reporters.JUnitXMLReporter;
import org.uncommons.reportng.HTMLReporter;
public class SampleTestSuite
{
public static void main(String[] args)
{
HTMLReporter rep = new HTMLReporter();
JUnitXMLReporter jxr2 = new JUnitXMLReporter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { CarTest.class,
CustomerTest.class });
testng.addListener(rep);
testng.addListener(jxr2);
testng.run();
}
}
Please let me know if i have went wrong somewhere.
Thanks
Prakash
> On Sun, May 2, 2010 at 8:39 AM, Prakash <
rushtoprak...@gmail.com> wrote:
>
> > When all iterations of data provided test passes, the HTML report
> > displays the complete details i.e. all five assertion details.
> > When i make one of the iteration's assertion fail, the HTML report
> > displays only the two failed assertions and one of the passed
> > assertion. I don't know why two other passed assertion detail is not
> > displayed in the final report. Can someone help me how to get all
> > assertion details.
>
> This should not be happening: if an invocation of a data provider fails, it
> should be reported as such and all the others should be successes. I wrote
> a quick test to confirm:
>
> PASSED: ctest1(42)
> PASSED: ctest1(43)
> PASSED: ctest1(45)
> PASSED: ctest1(46)
> FAILED: ctest1(44) <-- I failed that one
>
> I also verified that the HTML report shows this result as well.
>
> Can you send me the code of your test class showing the bug?
>
>
>
> > I have one more question, how can i get a JUnit style report when i am
> > running the tests from Java code like above and not using testNG.xml.
>
> TestNG generates an XML file that's compatible with JUnitReports, take a
> look at this section of the
> documentation<
http://testng.org/doc/documentation-main.html#logging-junitreports>
> .