簡體   English   中英

Visual Studio 2012 - 單元測試錯誤

[英]Visual Studio 2012 - Unit Test Error

我正在使用Visual Studio 2012,我遇到以下錯誤:“錯誤'hw02.World'不包含帶有2個參數的構造函數。我正在嘗試為我的類創建單元測試:

class World : IWorld
{

    public World(int width, int height)
    {
        Width = width;
        Height = height;
        world = new IBuilding[width, height];
    }
}

創建錯誤的測試:

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var world = new World(5, 5); // this line creates the error: 'hw02.World' does not contain a constructor that takes 2 arguments
    }
}

謝謝你的幫助

World是一個Internal類(在類級別沒有Public關鍵字),如果您的單元測試不在同一個程序集中,並且這些程序集之間沒有InternalsVisibleTo關系,那么您的單元測試將看不到任何公共構造函數和因此抱怨沒有帶有兩個參數的構造函數(從Test程序集的角度看這是真的)。

請參閱有關默認可見性的文檔。

class World public class World設為public class World或將InternalsVisibleTo屬性添加到包含World類的程序集。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM