+ Start a Discussion
jhansisridhar_2011jhansisridhar_2011 

Test coverage to satisfy if condtion

How to get satisfy the if condition so which not able to cover

 

XmlStreamReader r = new XmlStreamReader(xmlInput);


if ('Product' == r.getLocalName()) {

.

.

.

}

 

Thanks in Advance.

RoyGiladRoyGilad

You just create a string and call your function:

 

String xmlInput= '<Product>Foo bar</Product>' ;

function(xmlInput);

 

Does that help?

 

jhansisridhar_2011jhansisridhar_2011

Hi Roy,

 

I tried ur method, thrown an error

Error: Compile Error: Method does not exist or incorrect signature: function(String) at line 54 column .

 


SamuelDeRyckeSamuelDeRycke

The point wasn't to just copy paste the line.

 

Assuming the code you are testing is in a method, its getting that xmlinput string from somewhere, if not, handle it in a method that accepts a parameter, so you can submit test data into it.

 

So if you'd have:

private somemethodname void(string xlminput){
    XmlStreamReader r = new XmlStreamReader(xmlInput);

    if ('Product' == r.getLocalName()) {
         .
         .
         .
    }

}

 you could test doing:

String xmlInput= '<Product>Foo bar</Product>' ;
somemethodname(xmlInput);