none
Unit testing. what do you do when u dont know what the user is going to enter and what the return val will be?

    Question

  • Hello all,

    I have just started to learn how to write unit tests and here is my question. Lets say i want to test this method

    public Organization getOrgInfo(int orgid)
            {
                var org = (from o in dc.Organizations
                           where o.OrgId == orgid
                           select o).First<Organization>();

                return org;
                
            }

    I right click in VS and select create unit test. Visual studio creates this in my test project.

    [TestMethod()]
            public void getOrgInfoTest()
            {
                IDefaultView dview = null; // TODO: Initialize to an appropriate value
                DefaultPresenter target = new DefaultPresenter(dview); // TODO: Initialize to an appropriate value
                int orgid = 3; // TODO: Initialize to an appropriate value
                Organization expected = null;
                Organization actual;
                actual = target.getOrgInfo(orgid);
                Assert.AreEqual(expected, actual);
                Assert.Inconclusive("Verify the correctness of this test method.");
            }

    Now based upon my reading from this link:

    http://msdn.microsoft.com/en-us/library/ms182532%28v=VS.90%29.aspx


    It seems like I would have to know the exact value of the Organization object which of course isnt known because the values for this are not known. The returned list will change over time.. So to solve this issue I was wondering can i comment out assert.areequal because again i dont know what to expect for my returned object.


    Thanks in advance


    Monday, August 23, 2010 7:06 AM

All replies

  • Update:

    I changed the above to this so that the expected and actual are equal.

    IDefaultView dview = null; // TODO: Initialize to an appropriate value
                DefaultPresenter target = new DefaultPresenter(dview); // TODO: Initialize to an appropriate value
                int orgid = 3; // TODO: Initialize to an appropriate value
                Organization expected = target.getOrgInfo(orgid); // TODO: Initialize to an appropriate value
                Organization actual;
                actual = target.getOrgInfo(orgid);
                Assert.AreEqual(expected, actual);


    Monday, August 23, 2010 7:11 AM
  • So is there anything i can do with Assert.Inconclusive?

    Monday, August 23, 2010 7:12 AM