views:

69

answers:

1

I have some test code that looks like this:

[Test]
public void RunTableInfoCommandShouldCallTableINfoWithName()
{
   string expectedcommand = "TableInfo(TestTable,1)";

   Table.RunTableInfoCommand(mockmapinfo.Object,
                            "TestTable",
                             TableInfoEnum.TAB_INFO_NAME); //This is just an enum for 1.

   mockmapinfo.Verify(m => m.Evaluate(expectedcommand));
 }

Should I be creating a test with a mock object just to see if the expected command that is used by the mock is called in RunTableInfoCommand

Or should I just have a test that checks the output of RunTableInfoCommand and use the mock there because that would test to see if the call is made also.

RunTableInfoCommand returns a string, as you can see I haven't used it here because I just want to see if the TableInfo command is even called.

+2  A: 

I don't think you should test for to see if the function you are calling is called. You should assume that it will.

What you may be best doing is testing the behaviour. For example setup a test that has a function that calls RunTableInfoCommand as part of its expected behaviour.

Then check the result is what you expected.

e.g.

[Test]
public void GetTableName()
{   
    string expectedName = "TableInfo(TestTable,1)"; 
    Assert.AreEqual(testTable.GetTableName(mockmapinfo.Object) = expectedName); 
}

In this example, GetTableName would actually be the function that calls RunTableInfoCommand. So you are testing an interface or behaviour of an object.

Hope this helps.

dean nolan