views:

291

answers:

8

My boss wants me to create an .aspx page, textboxes for simplicity for entering credit card information so we can test out some methods in our CreditCard service.

Thats fine but I would think we could do a Unit test for this. The only thing is, instead of typing the stuff into a web form, we'd just change the variable values passed into the unit test.

Can anyone tell me if we're crazy for not doing a Unit test instead of an .aspx page for testing and entering in test data to test out some calls to some of our methods?

He'll end up telling me Unit Test takes too much time to setup (as I've tried to tell him we need to do unit testing) which is a lame stupid excuse.

A: 

Instead you can write a simple .NET(or Java) test that calls the web service and checks various scenarios, along with the obvious benefit (it's testable) you will also have an automated way to check its functionality.

The time "wasted" on writing the unit tests will be regained by the time saved on testing the same scenario over and over again instead of just running the automated tests.

If your boss is not convinced by that point him to studies that show TDD/unit tests effectiveness.

If all else fails why not use an automatic tool like soapUI at least you'll save yourself from manually testing the same functionality over and over again.

Dror Helper
yep, I told him we can just re-run these tests later.
CoffeeAddict
CoffeeAddict
Then you should offer using a soap "automation" framework - see above
Dror Helper
+7  A: 

You are crazy if you don't unit test your web service instead of writing a manual testing harness :)

Basically, a web service is an API that is accessed over a remote protocol, so why not unit test it?

Mark Seemann
It is a crazy world alright :)
Thiyagaraj
Agreed. Test the code outside of the webservice publication... that layer is mostly just configuration. The thing that counts is the code. Write unit tests for everything there. You will be glad you did.
Brian Genisio
See also my other, more seriouse answer on this page...
Mark Seemann
A: 

In my opinion, if you create .aspx page and get value from web form, it would be more real time testing than unit testing. I hope web service was already unit tested by the organization, which provide you this web service. I think, you just need to create .aspx form and get done your work.

You can do unit testing for your entire development process satisfaction. It is good idea that unit test should be done by the person who wrote the code of class/function/web method.

Let me know, if you have any question.

Syed Tayyab Ali
we created the web service for consumption internally.
CoffeeAddict
Unit testing should not be a "for your satisfaction". It's for the entire team and to improve testing, coding, and much more.
CoffeeAddict
>>it will not take too much time. Well that depends if you're a beginner or not in Unit testing.
CoffeeAddict
As far as my understanding, developer should always write unit test, what ever they coded.
Syed Tayyab Ali
+2  A: 

If it's an ASMX web service, you might try enabling the HttpPost protocol in your Web.config:

<configuration>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
  </system.web>
</configuration>

This will enable the test form for the web service when you visit the .asmx page in your browser. It might not work well for complex types; but if you have complex types, it'll be easier to build the unit tests than a custom form anyway.

The argument that unit testing is harder than a web form seems wrong; if you're developing a form, you have to write the web service client code anyway, in addition to building the page itself.

mogrify
exactly, you're doing double work. You have to create a form outside of just the testing logic.
CoffeeAddict
+3  A: 

Your boss may wish to confirm that the web service can be called from an .aspx page as well as being able to try out some values. (Does he want example calling code that someone else to use to create the real web page?) If your web service calls any external services and/or uses a database it will be hard to write automated unit tests for it anyway.

As to writing a real unit test for the web service, I think you have already lost the battle this time….

Next time, try writing unit tests for each method the web services calls, just before or just after you write the method. There is no need to even tell your boss you are doing this, as it will result in producing working code quicker.

Once you have proved the unit tests help you write better code quickly you can try to introduce Test Driven Development and/or have the unit tests check into the source code control system and other people run them when they change the code.

You could always spend some of your own time tonight, after your boss has gone home, trying to write the unit tests. Then only tell him what you have done when he ask why your code has no bugs in it.

Ian Ringrose
the methods being called does talk to a database but I'm talking about testing the method calls, not the database calls here. And anyway if I wanted to truly test those service methods that send updates/gets to a database, I could mock.
CoffeeAddict
I like your approach of doing it anyway outside of work. It will at least help me in the long run if I cannot convince this place currently.
CoffeeAddict
A: 

It is a battle you'll surely loose. You have to put yourself in your bosses shoes. There are projects where unit testing could take up too much time, especially at the end of the development cycle when everything is rushed to be completed. TDD has to be followed from the start or you will loose too much time implementing unit tests after you have already forgotten how a specific piece of code works (no, comments are usually not enough).

Just make it common practice for next projects that you do TDD. After you have all of your code unit tested you could implement some type of functional testing with tools such as JMeter and Selenium.

Miha Hribar
yea and I'm trying to start NOW.
CoffeeAddict
we have no tests period.
CoffeeAddict
>>>It is a battle you'll surely loose. You have to put yourself in your bosses shoes. I disagree. Good managers know to incorporate or at least look at this option as it's a great process in IT. Bad managers are the ones who give excuses not to push back for the sake of doing testing for the team and the business. I don't care if my manager is under pressure or his lack of ability to slow down and do things with standards kick in each day. I care about doing things right and to save time and frustration in the long run. So no, I will not because that person only cares about running
CoffeeAddict
CoffeeAddict
So I have no sympathy for that manager who totally disregards the idea which benefits the company overall in the long run due to lame excuses or reasons that "it slows us down"
CoffeeAddict
What I meant was that on some projects where unit testing is introduced too late, there is no time for unit testing. You have to make with what you already have.
Miha Hribar
A: 

Guessing that you already lost the battle (we feel for you). There are better solutions than manually creating a consumer for your web service.

Check out SoapUI. It consumes your WSDL and lets you play with the xml requests. Very easy to plug into a web service to test it out if all they want is a POC.

Ty
+3  A: 

I feel a little bit guilty about leaving such a glib answer as I did before, so here's a more serious take on it:

Let's examine what it would take to unit test the service. A real unit test is an automated test that tests a single unit (in your case that would the web service without any backend systems such as databases etc.). As others have pointed out, proper unit testing of the service is probably too late in this case.

That doesn't mean that you can't use a unit testing framework (such as MSTest, xUnit.net, NUnit, etc.) to drive your service tests. Let us contrast that scenario to developing a throw-away aspx page:

  • In both cases I am going to assume that the web service is already deployed, configured and running, because that would probably be the case in the aspx scenario.
  • In both cases you would have to add a service reference to the test project to generate a web service proxy.
  • In both cases you would have to write code that applies values to the request parameters for the web service methods.
  • In both cases you need to invoke the web service operations.

So what's different?

  • In the aspx scenario, you will need to collect values from form fields and assign those values to to the service method paramters. Using a testing framework, you can write those values directly. It's actually easier to write the automated test. 1-0
  • In the aspx scenario, you would need to write code that takes the response data and write it to the web page. In contrast, with a testing framework, you will need to write assertions. I would claim that it's easier to write assertions, but that's a bit subjective so I'll leave this one as a tie - still 1-0
  • In the automated test scenario, you will need to write many tests with different values, so that's more code you will need to write compared to the aspx option. 1-1
  • With an automated test suite, you can subsequently run the automated test suite against the database many times a day with no additional effort, whereas you would need to manually input and manually verify the results in the aspx scenario for every test run. That's a huge win in testing effort. 2-1 (and that's conservative)

In conclusion, I would say that if you don't insist on doing real unit-testing in this case, but simply utilize a unit testing framework to write automated tests, you should be better off with the automated tests than with the aspx page. The development effort will be more or less the same.

For your next project, you can then see if you can use TDD from the beginning, but that's another battle.

Good luck.

Mark Seemann
>>>>In the aspx scenario, you would need to write code that takes the response data (not with these calls, they return an int or boolean back)
CoffeeAddict
CoffeeAddict
CoffeeAddict
What about setting up that aspx page and running testing via a tool like Selenium or JMeter (link in my answer below)? Grant it you would need to change the Selenium tests when you web service changes, but you could still run it on demand with measurable results. In case of Selenium you could even use the Firefox plugin to ease the creation of "unit tests".
Miha Hribar