单元测试意识与软件质量
作者:网络转载 发布时间:[ 2011/9/14 13:45:18 ] 推荐标签:
测试类:(ConnectionFactoryFixture.cs) 主要测试了CreateConnection这个方法的逻辑分支,以及抛出的各种异常。
using System;
using System.Text;
using System.Collections.Generic;
using NUnit.Framework;
using Microsoft.Practices.SmartClient.ConnectionMonitor.Implementations;
namespace Microsoft.Practices.SmartClient.ConnectionMonitor.Tests
{
/// <summary>
/// Summary description for ConnectionFactoryFixture
/// </summary>
[TestFixture]
public class ConnectionFactoryFixture
{
public ConnectionFactoryFixture()
{
}
[Test]
public void CanCreateDesktopConnection()
{
Connection connection = ConnectionFactory.CreateConnection("DesktopConnection", 1);
Assert.IsNotNull(connection);
Assert.IsTrue(connection is DesktopConnection);
}
[Test]
public void CanCreateNicConnection()
{
Connection connection = ConnectionFactory.CreateConnection("NicConnection", 1);
Assert.IsNotNull(connection);
Assert.IsTrue(connection is NicConnection);
}
[Test]
public void CanCreateWirelessConnection()
{
Connection connection = ConnectionFactory.CreateConnection("WirelessConnection", 1);
Assert.IsNotNull(connection);
Assert.IsTrue(connection is WirelessConnection);
}
[Test]
public void CanCreateWiredConnection()
{
Connection connection = ConnectionFactory.CreateConnection("WiredConnection", 1);
Assert.IsNotNull(connection);
Assert.IsTrue(connection is WiredConnection);
}
[Test]
public void CanCreateMyCustomConnection()
{
Connection connection = ConnectionFactory.CreateConnection("Microsoft.Practices.SmartClient.ConnectionMonitor.Tests.MyCustomConnection,SmartClient.ConnectionMonitor.Tests", 1);
Assert.IsNotNull(connection);
Assert.IsTrue(connection is MyCustomConnection);
}
[Test]
[ExpectedException(typeof(ConnectionMonitorException))]
public void CreateConnectionThrowsWhenPassedBadType()
{
Connection connection = ConnectionFactory.CreateConnection("BadTypeName", 1);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void CreateConnectionThrowsWhenPassedNullType()
{
Connection connection = ConnectionFactory.CreateConnection(null, 1);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void CreateConnectionThrowsWhenPassedEmptyType()
{
Connection connection = ConnectionFactory.CreateConnection(String.Empty, 1);
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void CreateConnectionThrowsWhenPassedNegativePrice()
{
Connection connection = ConnectionFactory.CreateConnection("WiredConnection", -1);
}
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11