cancel
Showing results for 
Search instead for 
Did you mean: 

Null Value testing

SOLVED
New Contributor

Null Value testing

I have 3 input parameter in SOPA project. I want to test what happens when a null value is passed to one of the string.
Is there a way to pass a null string.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lib="foo.com">
<soapenv:Header/>
<soapenv:Body>
<lib:foo>
<lib:fooA>?</lib:lib:fooA>
<lib:lib:fooB>?</lib:lib:fooB>
<!--Optional:-->
<lib:lib:fooC>If I leave it as empty it's going as string.Empty in the code. I want the value to be null.</lib:lib:fooC>
</lib:foo>
</soapenv:Body>
</soapenv:Envelope>

Tried below method - Did not work.

xsi:nil="true"

 

C#code behind:

[webmethod]
public bool foo(String a, String b, String c)

{


If( c == null)
I want this condition to be a success for the testing.

}


Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Null Value testing

In this case you are actually asking a question about the C# side of your code, so I'm not sure you can get a definitive answer here. In XML, xsi:nil="true" does represent a NULL, but your C# library might be returning a different value. It may not be one of the potential results for your library at all, in which case you don't have a valid test case.

 

The things to test for from the client side is how your API will respond to each of ....

<lib:lib:fooC></lib:lib:fooC>
<lib:lib:fooC/>
<lib:lib:fooC xsi:nil="true"/>

Remember, your xml document must include the name space declaration:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<!-- lib:lib:fooC/-->

(There may be no difference between the first two).

 

If all of these get the response you expect, and none of them trigger that branch in your C# code, then it probably is just dead code (code that will never be called) and probably should be removed.

3 REPLIES 3
Community Hero

Re: Null Value testing

In this case you are actually asking a question about the C# side of your code, so I'm not sure you can get a definitive answer here. In XML, xsi:nil="true" does represent a NULL, but your C# library might be returning a different value. It may not be one of the potential results for your library at all, in which case you don't have a valid test case.

 

The things to test for from the client side is how your API will respond to each of ....

<lib:lib:fooC></lib:lib:fooC>
<lib:lib:fooC/>
<lib:lib:fooC xsi:nil="true"/>

Remember, your xml document must include the name space declaration:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<!-- lib:lib:fooC/-->

(There may be no difference between the first two).

 

If all of these get the response you expect, and none of them trigger that branch in your C# code, then it probably is just dead code (code that will never be called) and probably should be removed.

New Contributor

Re: Null Value testing

Thank you @JHunt

Guess you must be right. On trying all your suggestions always returns an empty string. So my C# library always returns an empty string since it's a string value in my API.

New Contributor

Re: Null Value testing

Thank you @JHunt.

I guess you might be correct. On trying all your suggestions, I always get an empty string in my C# code side.
My C# library should to taking care of null as an empty string since the API parameter is a string.


New Here?
Join us and watch the welcome video:
SmartBear + Cucumber