+ Start a Discussion
jhansisridhar_2011jhansisridhar_2011 

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.

shravanshravan

Hi,

 

Create object for that class and call that method.

Ex:

Class
------------

class xxx {

   ...

   public void storeProducts() {

   ....

   }

}

 

Test Method:

------------------

class Test_xxx {

   ...

   static TestMethod void storeProducts () {

    xxx object = new xxx();

    object.storeProducts();  

   }

}

 

jhansisridhar_2011jhansisridhar_2011

Hi Sravan,

 

Thanks for Reply.

 

Not helped me to increase in code coverage.