1

My original question was to how to get method call counts. From the answers here, I gather that what I should be asking is what profiler output allows you to extract its information to get method call counts, and use that information in my integration tests.

Update: This is the application, I don't see how, or why I would want to add extra code to it for the sake of testing it. I don't mind writing code external to the site. We have integration tests that do not use the UI. Those tests pass, yet when accessed from the UI something somewhere has made an inappropriate call, circumventing caching. It's not noticeable on visual inspection. And up to this point, has never been tested in any of our UI tests (we use Selinium). I would imagine some sort of profiler would work, but I am not familiar with profilers. Much less how to log the information they produce and validate it within an automated test.

Charles Lambert
  • 5,042
  • 26
  • 47
  • So, am I understanding that your question is really whether you can capture the results of running a code profiler in an automated test? – neontapir Apr 20 '11 at 16:29
  • From what I've been reading, I think so. I've never really used a profiler before so I can't be certain. – Charles Lambert Apr 20 '11 at 19:19

2 Answers2

0

Unless you could get a profiler to capture this data for you, you'll need to add code to capture the number of calls. The Visitor design patten is a good approach to handle situations like this. An IoC container could help you inject the Visitor into the appropriate classes.

neontapir
  • 4,698
  • 3
  • 37
  • 52
  • Pretty unsure about IoC. Doesn't it make an already-built project just more complicated than before? I mean, if he was in design phase it would have been a great idea, but now he would need to review the whole code and possibly introduce mistakes... – usr-local-ΕΨΗΕΛΩΝ Apr 19 '11 at 18:56
  • how would a visitor pattern help me count the number of calls to a method? – Charles Lambert Apr 19 '11 at 20:34
  • @djechelon, you have a good point about introducing new code. I would not advocate adding an IoC container for this, I'm just saying it would complement the use of the Visitor pattern. – neontapir Apr 20 '11 at 16:22
  • @Charles, in a sentence, the Visitor pattern has you add a call to a second method in your code as a hook that you can use to extend the method without altering it. In this case, the second method would include a counter. Another approach would be a Decorator, in which you'd wrap the original class with one that does the counting and defers the work to the original class. – neontapir Apr 20 '11 at 16:26
  • I don't think adding code specifically for testing is a good idea. However getting output from a profiler and parsing it is a good idea. – Charles Lambert Apr 29 '11 at 14:44
0

Nothing wrong with adding code to capture this kind of data. I've used the Trace.write() method for this exact thing in the past. If tracing isn't enabled there is no performance hit at all.

Edit: You can enable page tracing by adding Trace=True in your @Page directive. http://msdn.microsoft.com/en-us/library/94c55d08.aspx then when you request the page, you'll see a big list appended to the bottom with all of the trace statements. There are a ton of other options that you can use to configure it if you don't want it to show up in the page (ie. send it to a log file)

Trace statements shouldn't be considered "testing", as you'll see in the output there is already of ton of tracing going on already in the core .net assemblies.

Al W
  • 7,539
  • 1
  • 19
  • 40