嘗試單元測試某個類項目的一些簡單代碼,但是在我的測試代碼中 - 它一直告訴我我的InventorySelect找不到。它問我是否缺少使用聲明等,但就我所見,這一切都是正確的。c#,找不到類型?
我的代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Home
{
class InventoryType
{
/// <summary>
/// Selects the inventory type and returns the selected value
/// </summary>
public class InventorySelect
{
private string inventoryTypes;
public String InventoryTypes
{
set
{
inventoryTypes = value;
}
get
{
return inventoryTypes;
}
}
/// <summary>
/// Validate that the inventory is returning some sort of value
/// </summary>
/// <returns></returns>
public bool Validate()
{
if (InventoryTypes == null) return false;
return true;
}
}
}
}
我的測試代碼
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Home.InventoryType.InventorySelect;
namespace HomeTest
{
[TestClass]
public class TestInventoryTypeCase
{
[TestMethod]
public void TestInventoryTypeClass()
{
InventorySelect select = new InventorySelect();
select.inventoryTypes = "Collection";
if (Validate() = true)
Console.WriteLine("Test Passed");
else
if (Validate() = false)
Console.WriteLine("Test Returned False");
else
Console.WriteLine("Test Failed To Run");
Console.ReadLine();
}
}
}
你意外地嵌套你的類。內部類稱爲'InventoryType.InventorySelect'。 – CodesInChaos
CodesInChaos說,你嵌套你的類。此外,任何C#類的默認可見性都是內部的,因此InventoryType對測試項目不可見。 –
@CodesInChaos發表您的評論作爲回答 –