I have a particular method called TranslateValues() (Cyclomatic-Complexity of 5) which I would like to test.
The test requires a substantial number of mock objects which take up most of the method; The method being tested is fairly straightforward with this exceptional requirement. I am suspicious of this. For me, I might do something like this to alleviate the issue:
namespace TestArea
{
[TestClass]
public class PrimaryTests
{
//commonly used classes should go up here
private CoreServiceClient client;
public CoreServiceClient Client
{
get { return client; }
set { client = value; }
}
[TestMethod]
public void TestMethodForXYZ()
{
try
{
//use the Client, do some stuff, and assert
}
catch
{
//catch any problems, report them, and assert.fail
}
}
}
}
But this will only take you so far in reducing the size and clutter of test methods, and so it begs the question: Are big test methods generally indicative of code smell? How do you gauge when your methods are becoming too big?