We're in a process of writing Test framework (for Integration Testings) and I have a question regarding asserts. The test code looks like that:
public class MyTestClass
{
[Fact]
public void MyTest()
{
CreateEntity();
DeleteEntity();
}
}
The framework code looks like that:
public class CRUD
{
public bool CreateEntity()
{
FuncA();
FuncB();
FuncC();
FuncD();
}
}
If FuncA()
fails I don't want to run FuncB()
, FuncC()
or FuncD()
.
What I usually would do, is to check if FuncA()
executed successfully using if-else sentence, and if not - I would have return false.
My problem is that the person who write the Test-Code have to manually check if CreateEntity()
return true or false. Because it's a test code, if CreateEntity()
fails, there is no real meaning to continue the Test-run. I don't want the user to if-else every method on his Test-Case and assert on failure. Can I do the assert myself in the Framework method? for example -
public class CRUD
{
public bool CreateEntity()
{
if (FuncA() == false)
{
Assert.True(false, "FuncA() has failed");
}
FuncB();
FuncC();
FuncD();
}
}
Is that considered a good idea? or the user should anyway do the inquiring himself? I want the creation of Test-Cases to be easy as possible to the user.
Thanks!
EDIT: Important thing to remember is this is an Integration Test Framework. Unlike Unit-Tests, we are performing various actions and try to see how they all work together. FuncA() go to the server and try to perform an action. This action should not normally fail. If it has some major basic functionality bug, it will be caught on our Unit-Test run. When it doesn't work in our Integration run - It might point to a bug that happens after specific set of previously made actions. So we want to know about it, and stop the test as the next actions will probably not work as they are integrated one into the other. So I'm not sure we want to mock "CreateEntity", as it gives us information about illness in the system. I do agree with you that Assert is not the right way to handle it, I'm just not completely sure exception is the right way to go, as I don't want to handle the problem, I want to report it and stop the test. I'm not too fond of the other option that requires the user to if/else every framework call and check for the results (which will create a messy code in my own opinion).