I am using Visual Studio 2012 and I'm having the following error :"Error 'hw02.World' does not contain a constructor that takes 2 arguments. I'm trying to create unit test for my class:
class World : IWorld
{
public World(int width, int height)
{
Width = width;
Height = height;
world = new IBuilding[width, height];
}
}
The test which creates the error:
[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
}
}
Thanks for any help
World is a Internal class (does not have a Public keyword at the class level), if your unit test isn't in the same assembly and if there is no InternalsVisibleTo
relationship between these assemblies, your unit test will not see any public constructor and thus complain that there is no constructor with two arguments (from the perspective of the Test assembly this is true).
See the documentation on Default Visibility .
Either make the class World
a public class World
or add an InternalsVisibleTo
attribute to the assembly that contains the World
class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.