473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UnitTest

Hi, i have included throw new exception in my webservice, when i am trying to test webservice, passing baddata, and step into code in webservice, obviously it is jumping into throw exception. but not to the line Assert.isfalse in my test project.

Expected behaviour: when i pass baddata, after going through webmethod it shud go to next line that is Assert.method.isfasle().

but it is going to catch in my test project,giving me a soap exception.

Here i should raise soap exception in my project and be able to test my webservice with badata. Ny idea???? ASAP :( plss
Sep 25 '08 #1
7 1873
nateraaaa
663 Expert 512MB
Depends on what Unit Testing tool you are using but all tools should allow you to specify the type of exception the method should throw. Below are examples for NUNIT and Visual Studio Team Test:

NUNIT
[Test]
[ExpectedException(typeof(MembershipCreateUserExcep tion))]
public void ValidateUserReturnsFalseWithBlankPassword()
{
mockService.ExpectNoCall(“ValidateCredentials”);
provider.ValidateUser(“Someone”, “”);
mockService.Verify();
}

Visual Studio Team Test
[TestMethod][ExpectedException(typeof(ArgumentException),"A userId of null was inappropriately allowed.")]
public void NullUserIdInConstructor()
{
LogonInfo logonInfo = new LogonInfo(null, "P@ss0word");
}
Nathan
Sep 25 '08 #2
I am using VS2008 Unit testing. Could you pleaseexplain me in detail..?

Thanks.
Sep 25 '08 #3
nateraaaa
663 Expert 512MB
I am using VS2008 Unit testing. Could you pleaseexplain me in detail..?

Thanks.
Are you using the ExpectedException tag in your test?
Sep 25 '08 #4
hey i got it...yeah i have to use expectedexception.

Thanks for your reply,.
Sep 26 '08 #5
hi urgent query pls.

I could not test my webservice normally using Assert.issame or wtever. as it is throwing a soap exception from my webservice.
I am trying to od like this, catch exception and inside catch, will compare which is the exception that is thrown, i have some 8 exception msgs. Now if any of them occurs i am making it to go through assert.inconclusive and return a srtring message.is it right? or is there any other way to do this. could anyone please let me know.
Sep 26 '08 #6
Curtis Rutland
3,256 Expert 2GB
Please don't double post your questions. If you made a mistake and need to change your question, you can click the Edit button to edit your post, or you can post your corrections in a reply to your original thread. If you can't find your original thread, click the "My Subscriptions" link near the top of the page. If you feel that your question has been overlooked, post a reply to it to "bump" it back to the top of the forum. We ask that you do this only once every 24 hours.

So there is no reason to double post. It makes it hard on the Experts and you to keep track of what help you've already been given.

I have merged your threads.

MODERATOR
Sep 26 '08 #7
nateraaaa
663 Expert 512MB
hi urgent query pls.

I could not test my webservice normally using Assert.issame or wtever. as it is throwing a soap exception from my webservice.
I am trying to od like this, catch exception and inside catch, will compare which is the exception that is thrown, i have some 8 exception msgs. Now if any of them occurs i am making it to go through assert.inconclusive and return a srtring message.is it right? or is there any other way to do this. could anyone please let me know.
You should write separate catch blocks for each possible type of exception that could be thrown.

Expand|Select|Wrap|Line Numbers
  1. catch(SoapException soapExc)
  2. {
  3. }
  4. catch(IndexOutOfRangeException outOfRangeException)
  5. {
  6. }
//etc

Then you should write a test for each type of ExpectedException that could be thrown by your code. A unit test for each type of exception in your catch blocks.

Check the site below for common exception type in .NET
http://blogs.msdn.com/brada/archive/2005/03/27/402801.aspx

Nathan
Sep 26 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Will Stuyvesant | last post by:
I have a unittest testfile like this: ----------------------- test_mod.py --------------------- import sys sys.path.append('..') import unittest import mod class...
0
by: Danny Shevitz | last post by:
Why doesn't the following code snippet work? The error is ImportError: No module named myTestCase2 TIA, Danny %<--------------------------------------------------------------------
0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
1
by: Thomas Heller | last post by:
I'm trying to integrate some doctest tests with unittest. The tests must be exposed as one or more subclasses of unittest.TestCase, so I'm collecting them with a call to doctest.DocTestSuite(),...
41
by: Roy Smith | last post by:
I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did. I'm starting a...
7
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
3
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
2
by: Oleg Paraschenko | last post by:
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and...
0
by: Chris Fonnesbeck | last post by:
I have built the following unit test, observing the examples laid out in the python docs: class testMCMC(unittest.TestCase): def setUp(self): # Create an instance of the sampler...
1
by: Chris Fonnesbeck | last post by:
I have a module for which I am trying to code a unit test. However, when I run unittest.main(), I get: In : import PyMC In : PyMC.unittest.main() ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.