为什么有些测试不会显示在NUnit Test Runner中?

时间:2014-07-08 23:01:40

标签: c# unit-testing nunit integration functional-testing

我不知道" NUnit Test Runner"是正确的术语,或者是NUnit GUI"或者是什么,但我在谈论的是:

enter image description here

我有六个测试应该显示在" Integration \ HHSClientIntegrationTests"但是,正如你所看到的那样,只有两个人这样做了,而我无法理解它,或者根本不知道为什么选择了一些而其他人被测试工具拒绝了。

这是测试代码:

using NUnit.Framework;
. . .

namespace HHS.Web.Tests.IntegrationTest
{
    [TestFixture, Category(DBPPCOMMON.UnitTests.Categories.IntegrationTest)]
    public class HHSClientIntegrationTests
    {

        // This one displays in the test runner
        [Test]
        public void TestHHSInterface()
        {
            var HHSClient = IOC.container.Resolve<IHHSClient>();

            var s = HHSClient.GetTestMessage("Sam (not Roger)", "Clemens");

            Assert.Greater(s.Value.Length, 0);
        }

        // This one displays in the test runner
        [Test]
        public void TestHHSDeliveryInterface()
        {
            var Delivery = IOC.container.Resolve<IHHSDelivery>();

            var i = Delivery.GetCount();

            Assert.Greater(i, 17); 
        }

    // The rest do NOT display in the NUnit test runner
    [Test]
    public void TestHHSDeliveryInvNumByIdInterface()
    {
        var Delivery = IOC.container.Resolve<IHHSDelivery>();

        var s = Delivery.GetDeliveryInvoiceNumberById(42);

        Assert.Greater(s.Length, 0);
    }

    [Test]
    public void TestHHSDeliveryItemInterface()
    {
        var DeliveryItem = IOC.container.Resolve<IHHSDeliveryItem>();

        var i = DeliveryItem.GetCount();

        Assert.Greater(i, 42);
    }

    [Test]
    public void TestHHSDeliveryItemInterfacePostPT109Data()
    {
        var DeliveryItem = IOC.container.Resolve<IHHSDeliveryItem>();

        Random rndm = new Random();
        int randomNum = rndm.Next(1000);
        var gwid = Guid.NewGuid().ToString();

        string dataPoints = String.Format("serNum{0};tx{0};siteNum{0};{1}.xml;PT109_user{0};tx_memo{1};file_beg{0};file_end{0}", randomNum, gwid);
        . . .
        Assert.IsNotNull(response);
    }

解决的接口(IHHSClient,IHHSDelivery和IHHSDeliveryItem)如下所示:

namespace HHS.Client
{
    public interface IHHSClient
    {
        HHSEntity GetTestMessage(String id1, String id2);
    }
}

......而且这个:

namespace HHS.Client
{
    public interface IHHSDelivery
    {
        int GetCount();
        Delivery GetById(int ID);
        String GetDeliveryInvoiceNumberById(int ID);
        IEnumerable<Delivery> GetRange(int ID, int CountToFetch);
        IEnumerable<Delivery> GetAll();
        Delivery Add(Delivery item);
        bool PostDelivery(int Id, string InvoiceNumber, decimal TotalAmount, string VendorID, string Site, string EditListOption, string RedemptionOption, bool AllowNewItems, string dbContext);
    }
}

......而且这个:

namespace HHS.Client
{
    public interface IHHSDeliveryItem
    {
        int GetCount();
        DeliveryItem GetById(int ID);
        IEnumerable<DeliveryItem> GetRange(int ID, int CountToFetch);
        IEnumerable<DeliveryItem> GetAll();
        DeliveryItem Add(DeliveryItem item);
        void InsertIntoPT109Data(string serialNum, string tx, string site_no, string xmlfile, string PT109_user, string tx_memo, string file_beg, string file_end);
        bool InsertIntoPT109Data(String stringifiedRecord);
    }
}

实现这些接口的类看起来像这样:

namespace HHS.Client
{
    public class RESTHHSClient : IHHSClient
    {
    . . .

        public HHSEntity GetTestMessage(String id1, String id2)
        {
            var res = RESTAPIClient.GET<HHSEntity>(null
               , new Uri(HHSClientSettings.HHSAPI)
               , String.Format("api/Test/{0}/{1}"
                                , id1
                                , id2)
                                );

            if (res.status != RequestResultStatus.Success)
            {
                throw new Exception(res.message);
            }

            return res.result; 
        }

    }
}

......而且这个:

namespace HHS.Client
{
    public class RESTHHSDelivery : IHHSDelivery
    {
    . . .

        String IHHSDelivery.GetDeliveryInvoiceNumberById(int ID)
        {
            var res = RESTAPIClient.GET<String>(null
               , new Uri(HHSClientSettings.HHSAPI)
               , "api/delivery/invnumbyid"
               );

            if (res.status != RequestResultStatus.Success)
            {
                throw new Exception(res.message);
            }

            return res.result;
        }

        int IHHSDelivery.GetCount()
        {
            var res = RESTAPIClient.GET<int>(0
               , new Uri(HHSClientSettings.HHSAPI)
               , "api/deliveries/Count"
               );

            if (res.status != RequestResultStatus.Success)
            {
                throw new Exception(res.message);
            }

            return res.result;
        }

......而且这个:

namespace HHS.Client
{
    public class RESTHHSDeliveryItem : IHHSDeliveryItem
    {
    . . .

        public int GetCount()
        {
            var res = RESTAPIClient.GET<int>(0
               , new Uri(HHSClientSettings.HHSAPI)
               , "api/deliveryitems/Count"
               );

            if (res.status != RequestResultStatus.Success)
            {
                throw new Exception(res.message);
            }

            return res.result;
        }

        public bool InsertIntoPT109Data(String stringifiedRecord)
        {
            bool success = true;
                var res = RESTAPIClient.POSTOBJECT_GETNOTHING<String>(null
                   , new Uri(HHSClientSettings.HHSAPI)
                   , "api/deliveryitems/InsertIntoPT109Data"
                   );

                if (res.status != RequestResultStatus.Success)
                {
                    success = false;
                    throw new Exception(res.message);
                }
            return success;
        }
    }
}

那么在测试列表中显示的那些(我应该说是两个)之间有什么不同呢?我确信这是一个合乎逻辑的解释,但在这个时刻,NUnit似乎与墨西哥无毛的百万富翁女继承人一样反复无常,不一致。

更新

当地的NUnit Whisperer看着它,结果发现Test项目的命令行参数&#34;价值是错误的;我们最近从TFS切换到Git,这仍然指向旧的(TFS)项目。

现在,随着val更新,所有测试都会显示,而应该失败的测试会显示。

0 个答案:

没有答案