• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

I need a hand. VS2010 unit test case use? How to? Desperate tester/coder...

Hi there;

I need a hand.

Ok, I try to create a test method to test my function in the given dll as follows (those are automatically created by VS2010).

But not sure, how to call the function/pass the parameters to test my function.

   [TestMethod()]
        [DeploymentItem("SomeDLL.dll")]
        public void myFunction()
        {
            string str= null; // TODO: Initialize to an appropriate value
            string input = string.Empty; // TODO: Initialize to an appropriate value
            string expected = string.Empty; // TODO: Initialize to an appropriate value
            string actual;
            actual = UniqueIdentifierGenerator_Accessor.myFunction(str, input);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

For the record, I didn't deal with testing before, so I need a basic need to understand the testing of the given function in the given project/dll.

I am talking about unit test case.

Regards.
0
jazzIIIlove
Asked:
jazzIIIlove
  • 4
  • 4
5 Solutions
 
MikeTooleCommented:
The TODO comments point out where to put the test values.
Assign input parameter values to the strings str and input.
Assign the expected result of the call to myFunction to the string actual.
From the Test menu select Run->All Tests in Solution.
0
 
jazzIIIloveAuthor Commented:
so, input parameters are the parameters that I input manually whereas the expected result is my inference of the possible result, true?

Kind regards.
0
 
MikeTooleCommented:
Yes, it has generated a call to your function using the values you assign to str and input:
    actual = UniqueIdentifierGenerator_Accessor.myFunction(str, input);
It the performs an Assert to compare the 'actual' result with whatever you assign to 'expected'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jazzIIIloveAuthor Commented:
ok, I got 2 other questions:

1) Where is the main to start testing in the respective cs file, yet, it's working. how?

I mean should I include the main function in the Program.cs that calls the function in UniqueIdentifierGenerator.cs having the function to test?

2) What is the meaning of :
Assert.Inconclusive("Verify the correctness of this test method.");

Should I remove this function call?

3) While I am creating the unit test with wizard and selecting the project and file(s) and function(s) to test, I have the following screenshot. Should I say Yes or No to this? What does that shot mean?

Regards.

1.png
0
 
tovvenkiCommented:
Hi,
With unit tests you do not need main, it will run automatically the method decorated with the TestMethod attribute
Also Assert.Inconclusive is used to  indicate an assertion that has not yet been implemented you can comment it out.

have a look at the following url to know more about unittesting with VS
http://msdn.microsoft.com/en-us/library/ms182515(v=VS.80).aspx
http://msdn.microsoft.com/en-us/library/ms243176(v=VS.80).aspx

Thanks and regards,
Venki
0
 
MikeTooleCommented:
1) Visual Studio has a run-time engine that exeutes tests, monitors progress and reports outcome, how it does it I don't know, except that all the tests must be in a separate test project.
2) It's just a reminder to check the validity of the automatically generated Assert() and should be deleted
3) If you want to test the internal / friend methods then the Test project needs authority to access them, so Yes would be the answer, see:
http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx
0
 
jazzIIIloveAuthor Commented:
>>If you want to test the internal / friend methods

who is friend or internal to whom?

I mean does my test project (the function in the test project) call for some reference in the real application?

Kind regards.
0
 
MikeTooleCommented:
A method (in the real application) that you want to set up a test for has scope internal (Friend in VB-speak) - i.e. it can't usually be accessed outside it's own project.
I believe that the answering Yes adds an attribute to the (real application) project to allow the Test project to call such methods.
0
 
jazzIIIloveAuthor Commented:
ok, thanks for the response.

Thanks for the contribution.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now