Question

I have a DataGrid which displays the available Classes and Methods in an Assembly. Here i ave attached the picture of dataGrid

alt text http://img150.imageshack.us/img150/5109/datagrid.png

Now my task is to Generate testCases based on the values in the DataGrid. Here are few test Cases.

     namespace proj.Test {
        using System;
        using NUnit.Framework;
        using proj;


        [TestFixture()]
        public class TestClass1 {

            [Test()]
            public virtual void Testadd1() {
                Class1 Class1 = new Class1();

                int a = 2147483647;
                int b = 2147483647;

            }

            [Test()]
            public virtual void Testadd2() {
                Class1 Class1 = new Class1();

                int a = 2147483647;
                int b = -2147483648;

            }

            [Test()]
            public virtual void Testadd3() {
                Class1 Class1 = new Class1();



                int a = 2147483647;
                int b = -2147483647;

            }

            [Test()]
            public virtual void Testadd4() {
                Class1 Class1 = new Class1();

                int a = 2147483647;
                int b = 2147483646;
    }
 }
 }

Now the problem, all values in the DataGrid are as String. I need to convert into types like System.Reflection.MethodInfo, System.Type etc so that i can generate such test cases?

How can I do it, or is there any other possibility to generate such testcases?

Was it helpful?

Solution

You shouldn't really take the values from the dataGrid itself, because this is just the UI control. Instead, you should find out where are they coming from (where the grid is populated) and hook up there. Then you will have all the data of correct types and hopefully it will not be UI dependent.

OTHER TIPS

Here's an MSDN article on data-driven unit tests:

http://msdn.microsoft.com/en-us/library/ms404708%28VS.80%29.aspx

There's a worked example there that includes using a database to store the values to plug into your unit tests.

I'd recommend against full code generation (i.e. code that generates your unit test bodies as well as the values to test with), as you end up putting code between your test cases and the tested code itself, which may lead to subtle inconsistencies or bugs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top