You need to sign in to do that
Don't have an account?
Help me to write test class for XMLStreamwriter.
Hi All,
Help me to write a test class for below code,
public void storeProducts(){
XmlStreamWriter w = new XmlStreamWriter();
w.writeStartElement(null, 'Product', null);
w.writeStartElement(null, 'Id', null);
w.writeCharacters(p.Id);
w.writeEndElement();
...............
..................
.............................
}
Test class: I have written test class as,
static TestMethod void storeProducts (){
XmlstreamWriter demo = new XmlstreamWriter();
string result=demo.getXmlstring();
string expected='<?xml version="1.0"?><?Products?>' + '<m:Product>' + '<00190000009rvgY>'; // is any other way to represent this line//
System.assert(result == expected);
}
Failure: System.AssertException: Assertion Failed
Thanks in Advance.
Hi,
You have to simply create the instance of class inside the test method and call that method through the instance of class inside the test method.
Try the below code as reference:
public class JustTestXML
{
public void storeProducts()
{
XmlStreamWriter w = new XmlStreamWriter();
w.writeStartElement(null, 'Product', null);
w.writeStartElement(null, 'Id', null);
//w.writeCharacters(p.Id);
w.writeEndElement();
}
static testmethod void testshowXML()
{
JustTestXML j=new JustTestXML();
j.storeProducts();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Navatar,
Thanks for reply and focusing on duplication of post.
but it's not helped me to increase code coverage .I need syntax in below pattern,
string expected='<?xml version="1.0"?><Products>'+'<m:Product>'; "something is going wrong here."