UnitTest

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • splendid9
    New Member
    • Mar 2008
    • 56

    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.i sfasle().

    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
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    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]
    [ExpectedExcepti on(typeof(Membe rshipCreateUser Exception))]
    public void ValidateUserRet urnsFalseWithBl ankPassword()
    {
    mockService.Exp ectNoCall(“Vali dateCredentials ”);
    provider.Valida teUser(“Someone ”, “”);
    mockService.Ver ify();
    }

    Visual Studio Team Test
    [TestMethod][ExpectedExcepti on(typeof(Argum entException)," A userId of null was inappropriately allowed.")]
    public void NullUserIdInCon structor()
    {
    LogonInfo logonInfo = new LogonInfo(null, "P@ss0word" );
    }
    Nathan

    Comment

    • splendid9
      New Member
      • Mar 2008
      • 56

      #3
      I am using VS2008 Unit testing. Could you pleaseexplain me in detail..?

      Thanks.

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        Originally posted by splendid9
        I am using VS2008 Unit testing. Could you pleaseexplain me in detail..?

        Thanks.
        Are you using the ExpectedExcepti on tag in your test?

        Comment

        • splendid9
          New Member
          • Mar 2008
          • 56

          #5
          hey i got it...yeah i have to use expectedexcepti on.

          Thanks for your reply,.

          Comment

          • splendid9
            New Member
            • Mar 2008
            • 56

            #6
            UNIT test

            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.inconclu sive and return a srtring message.is it right? or is there any other way to do this. could anyone please let me know.

            Comment

            • Curtis Rutland
              Recognized Expert Specialist
              • Apr 2008
              • 3264

              #7
              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

              Comment

              • nateraaaa
                Recognized Expert Contributor
                • May 2007
                • 664

                #8
                Originally posted by splendid9
                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.inconclu sive 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.

                Code:
                catch(SoapException soapExc)
                {
                }
                catch(IndexOutOfRangeException outOfRangeException)
                {
                }
                //etc

                Then you should write a test for each type of ExpectedExcepti on 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

                Comment

                Working...