function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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.