I am writing a bunch of integration tests for a project. I want to call each individual integration point method enclosed in a try / catch block, so when it fails, I get some feedback for the display, and not just the application crash. I also want to be able to time how much time should be taken, and check the return values ββwhen necessary. So, I have an IntegrationResult class with some basic characteristics, results, and time that passed the test:
class IntegrationResult { private StopWatch _watch; public string Description {get;set;} public string ResultMessage {get;set;} public bool TestPassed {get;set;} public string TimeElapsed {get { return _watch == null ? "0" : _watch.Elapsed.TotalMilliseconds.ToString(); } } public void Start() { _watch = StopWatch.StartNew(); } public void Stop() { _watch.Stop(); } }
The code that I continue to write is as follows:
IntegrationResult result = new IntegrationResult(); result.Description = "T-SQL returns expected results"; try { result.Start(); SomeIntegrationPoint("potential arguments"); //This is the line being tested result.Stop(); //do some check that correct data is present result.TestPassed = true; result.ResultMessage = "Pulled 10 correct rows"; } catch(Exception e) { result.TestPassed = false; result.ResultMessage = String.Format("Error: {0}", e.Message); }
I would really like to just pass the SomeIntegrationPoint method as an argument and delegate, or check the results something, but I canβt figure out if this is possible. Are there any frameworks for handling this type of testing, or do you have any suggestions on how I can simplify the code for better reuse? I'm tired of typing this block;)
source share