I'm using Visual Studio 2013 MSTest
JustMock Lite 2014.2.609.3 (via NuGet)
I'm trying to move the "MustBeCalled" expectations to TestCleanup.
Here is an example of code.
If I run the code as is, the test will pass (regardless if line 20 is commented or not).
This can be fixed by moving the Mock.Assert to line 22+ but ideally I would like to "auto call" Mock.Assert at the end of every test. I thought that adding it to TestCleanup would work but it doesn't appear to do so.
It appears that prior to TestCleanup running, JustMock will clear out the expectations prior to running TestCleanup.
Is there anyway around this?
Why am I doing this?
Because I'd actually like to write tests like this.
Of course my actual test classes will be more complex. But this approach allows me to Mock out MustBeCalled expectations in a more readable manner. Currently, the test author will have to remember to call Assert the _svc class (or _assertList) at the end of every TestMethod, but was hoping for a more maintainable solution.
Thanks
JustMock Lite 2014.2.609.3 (via NuGet)
I'm trying to move the "MustBeCalled" expectations to TestCleanup.
Here is an example of code.
01.
[TestClass]
02.
public
class
TestFixture
03.
{
04.
private
ICloneable _svc;
05.
06.
[TestInitialize]
07.
public
void
TestSetup() { _svc = Mock.Create<ICloneable>(); }
08.
09.
[TestCleanup]
10.
public
void
TestCleanup() { Mock.Assert(_svc); }
11.
12.
[TestMethod]
13.
public
void
TryStuff()
14.
{
15.
// arrange
16.
_svc = Mock.Create<ICloneable>();
17.
Mock.Arrange(()=> _svc.Clone()).MustBeCalled();
18.
19.
// act
20.
//_svc.Clone();
21.
22.
// assert
23.
}
24.
}
If I run the code as is, the test will pass (regardless if line 20 is commented or not).
This can be fixed by moving the Mock.Assert to line 22+ but ideally I would like to "auto call" Mock.Assert at the end of every test. I thought that adding it to TestCleanup would work but it doesn't appear to do so.
It appears that prior to TestCleanup running, JustMock will clear out the expectations prior to running TestCleanup.
Is there anyway around this?
Why am I doing this?
Because I'd actually like to write tests like this.
01.
public
class
TestFixture
02.
{
03.
private
List<
object
> _assertList =
new
List<
object
>();
04.
05.
[TestCleanup]
06.
public
void
TestCleanup() {
foreach
(var svc
in
_assertList) { Mock.Assert(svc); } }
07.
08.
private
void
CloneableMustBeCalled()
09.
{
10.
Mock.Arrange(() => _svc.Clone()).MustBeCalled();
11.
if
(!_assertList.Contains(_svc)) { _assertList.Add(_svc); }
12.
}
13.
}
Of course my actual test classes will be more complex. But this approach allows me to Mock out MustBeCalled expectations in a more readable manner. Currently, the test author will have to remember to call Assert the _svc class (or _assertList) at the end of every TestMethod, but was hoping for a more maintainable solution.
Thanks