简体   繁体   English

C# 关于数据网格的问题

[英]C# question about data Grid

I have a DataGrid which displays the available Classes and Methods in an Assembly.我有一个 DataGrid,它显示程序集中的可用类和方法。 Here i ave attached the picture of dataGrid这里我附上了dataGrid的图片

alt text http://img150.imageshack.us/img150/5109/datagrid.png替代文字 http://img150.imageshack.us/img150/5109/datagrid.png

Now my task is to Generate testCases based on the values in the DataGrid.现在我的任务是根据 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.现在的问题是,DataGrid 中的所有值都是字符串。 I need to convert into types like System.Reflection.MethodInfo, System.Type etc so that i can generate such test cases?我需要转换为 System.Reflection.MethodInfo、System.Type 等类型,以便生成这样的测试用例?

How can I do it, or is there any other possibility to generate such testcases?我该怎么做,或者有没有其他可能生成这样的测试用例?

You shouldn't really take the values from the dataGrid itself, because this is just the UI control.您不应该真正从 dataGrid 本身获取值,因为这只是 UI 控件。 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.然后您将拥有正确类型的所有数据,并希望它不会依赖于 UI。

Here's an MSDN article on data-driven unit tests:这是一篇关于数据驱动单元测试的 MSDN 文章:

http://msdn.microsoft.com/en-us/library/ms404708%28VS.80%29.aspx 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 (ie 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.我建议不要生成完整的代码(即生成单元测试主体的代码以及要测试的值),因为您最终会将代码放在测试用例和测试代码本身之间,这可能会导致细微的不一致或错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM