Reputation: 47743
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.
Upvotes: 7
Views: 5304
Reputation: 51917
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.
Upvotes: 3
Reputation: 233150
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:
So what's different?
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.
Upvotes: 6
Reputation: 3681
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.
Upvotes: 0
Reputation: 3948
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.
Upvotes: 0
Reputation: 5791
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.
Upvotes: 1
Reputation: 30790
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.
Upvotes: 0
Reputation: 505
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.
Upvotes: 3
Reputation: 233150
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?
Upvotes: 9