I have a couple of latency tests (basically unit tests) which test specific server APIs, and i have to know precisely how much time does it take from a request to response. the problem i have is that before calling a test, i must do some data initialization (for each test run, so if i do a latency test that runs 100 times, data must be initialized 100 times as well) which takes some time, but i don't want to count it.
There are 2 ways to initialize data : [MethodInitialization] and [ClassInitialization].
MethodInitialization - inits data before each run but when the test is finished, its duration = test initialization time + test run
ClassInitialization - inits data only once (which doesnt work for me), but test duration = test run
I know about stopwatch, but it will be very painful to use, as i also get data from AppInsights and would like to automate it as much as possible, and if i can have clear results after simple run, that would be just great.
Is there a way to initialize a test data before each test run but exclude its duration ?
UPD 1: I also tried to create my Custom Attribute, as there is way to do some actions in its constructor, but even when i run the test 10 times, attribute constructor is called just once.
I guess you need a professional tool like ANTS Performance Profiler. It will catch every single step of your routine (Class or Method) - and you can set "milestones" and discard others.
But, I'm thinking about what you mention above about the METHOD timing... I think it's the correct way to do it, since you cannot discard that step in your routine.
If I'm your client and your routine consumes a lot of time during the load of data but runs really fast, I will have the idea about the entire time to my judgement about performance. I won't separate your routine in two modules: its preparing and its execution.
I hope I had helped you some way. Good luck.