string str=System.Configuration.ConfigurationManager["connection"做岩液].ToString()//connection是纯物配置文件中的枣哪name
SQLConnection con=new SQLConnection(str)
app.config中设置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add connectionString="Data Source=Lilith-PC\SQL2005Initial Catalog=ManagementSoftwareIntegrated Security=True" name="connection"/>
</connectionStrings>
</configuration>
此外,注意app.config要放在表示层里
关键字: Unit Test, UI, NunitForms 工具: NUnitForms 使用简介:1. 下载NUnitForms后安装,然后还要安装NUnit2. 新建一个winform程序,在界面上加一个button和两个textbox,然后在不button1的click事件 private void button1_Click(object sender, EventArgs e) { textBox1.Text = "t1"textBox2.Text = "t2"} 下面来对上面这个界面程序编写单元测试,首先新建一个工程,类型为class library,添加如下引用nunit.frameworkNunitFormssystem.windows.forms上面创建的UI程序 下裂游型面是测试文件的代码using Systemusing System.Collections.Genericusing System.Textusing NUnit.Frameworkusing NUnit.Extensions.Formsusing WindowsApplication2namespace ClassLibrary1 { [TestFixture] public class TestForm: NUnitFormTest { private Form1 formprivate ButtonTester btnprivate TextBoxTester tb1private TextBoxTester tb2public override void Setup() { form = new Form1()form.Show()btn = new ButtonTester("button1")tb1 = new TextBoxTester("textBox1")tb2 = new TextBoxTester("textBox2")base.Setup()} public override void TearDown() { form.Dispose()base.TearDown()} [Test] public void TestButtonClick() { btn.Click()StringAssert.AreEqualIgnoringCase("t1", tb1.Text)StringAssert.AreEqualIgnoringCase("t2", tb2.Text)} } } 运行单元测磨梁试 打开Nunit,运行 例子下载:这里肆猜,其中包括了如何对模态对话框进行测试欢迎分享,转载请注明来源:内存溢出
评论列表(0条)