Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I've created unit tests of my WinForms using MS Visual Studio 2008. None of my tests have been approved. All of them (0/42 tests) resulted into some kind of failure described as follows:-

System.NullReferenceException: Object reference not set to an instance of an object.
Assert.Inconclusive failed. A method that does not return a value cannot be verified.

Without running these tests, the normal output produced didn't seem to throw any errors. I'm completely new to testing so I have no idea how to handle these errors.

EDIT:

/// <summary>
///A test for txtTel_Leave
///</summary>
[TestMethod()]
[DeploymentItem("Payroll master.exe")]
public void txtTel_LeaveTest()
{
    emp_Accessor target = new emp_Accessor(); // TODO: Initialize to an appropriate value
    object sender = null; // TODO: Initialize to an appropriate value
    EventArgs e = null; // TODO: Initialize to an appropriate value
    target.txtTel_Leave(sender, e);
    Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
share|improve this question
    
When you say approved do you mean passing? It might be useful to include an example of your code that you are trying to test and one of the tests. Based on the message is sounds like in part you still have the Assert.Inconclsive statements in the unit test, plus you may not be initializing the objects you are trying to test correctly from the test. Are you also trying to run unit tests on methods that return void? –  Dan Snell Jun 12 '13 at 17:50
    
Yes approved means passing. And yes, the tests are based on methods. –  deepz Jun 13 '13 at 8:39
    
You are getting errors because you have several values that are not initialized. For example object sender = null; Those values will need to be updated to something that is valid. It also looks like you might be trying to do this against an event handler (like a button click or something). which is probably not necessary. You will want to focus your tests on actual application logic. I am guessing you are new to c# as well? –  Dan Snell Jun 13 '13 at 16:19
    
I haven't C# for long time so I guess I haven't initialized (as you said). So I have to initialize objects from the code view, right? I'm sorry I am a beginner so please bear with me. –  deepz Jun 13 '13 at 17:31
    
Yes you will need to intitlaize the objects in the tests. You are passing null references into method from the test. Each of those //TODO flags indicates something where you will need to provide a value for the test. –  Dan Snell Jun 13 '13 at 17:39
show 2 more comments

1 Answer

up vote 2 down vote accepted

To set up your unit tests they need to initialize all of the variables. They should end up looking something like this:

Code To Be Tested:

public class Class1
{
    public int CombineValues(int a, int b)
    {
        int c = 12;
        if (a != 0 && b > 10)
        {
            c += (a + b);
        }
        else
        {
            c += 1;
        }
        return c;
    }
}

Unit Tests
Your values should be initialed and the test needs to assert something.

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void SimpleAdd()
    {
        int a = 1;
        int b = 12;
        Class1 cl1 = new Class1();
        int expected = 25;
        int actual = cl1.CombineValues(a, b);

        Assert.AreEqual(expected, actual);
    }

    [TestMethod]
    public void SimpleAdd_a_is_zero_test()
    {
        int a = 0;
        int b = 12;
        Class1 cl1 = new Class1();
        int expected = 13;
        int actual = cl1.CombineValues(a, b);

        Assert.AreEqual(expected, actual);
    }

}

For a far more comprehensive look at unit testing check out Roy Osherove's The Art of Unit Testing.

share|improve this answer
    
Thanks for your response :) –  deepz Jun 13 '13 at 18:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.