2

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.

zdebyman
  • 550
  • 1
  • 4
  • 22
  • If the purpose of your test is to assert that your APIs stay within a certain latency threshold, I can think of so mechanism better than Stopwatch to measure the latency, after which you can make the assertion you need. The solution I encountered at http://stackoverflow.com/questions/28334337/is-there-a-way-to-calculate-elapsed-time-for-test-methods-ignoring-time-spent-in depends on the test running in MSTest/VSTest. Is this what you are using to run your tests? – kbrimington Apr 08 '16 at 20:35

1 Answers1

0

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.

David BS
  • 1,822
  • 1
  • 19
  • 35
  • Thanks for your response, David. i cant use ANTS Performance Profiler, as its for ASP.Net solutions (as far as i can say), but what i have is just a server with bunch of REST APIs. Also this is the case where counting data initialization time is not an option, as it uses other API from the same server which have to be tested separately – zdebyman Apr 06 '16 at 22:24
  • Hmmm.... So, I guess your only unique option is work with Stopwatch and catch the results into a LIST to, after all run process, send it through RESPONSE to see results... – David BS Apr 06 '16 at 22:31