Thursday, March 15, 2018

Visual Studio 2012 Coded UI Test for Crystal Reports are too slow - how to speed them up

OK I have been getting really discouraged writing coded UI tests to test the output of Crystal Reports.

Seriously it was taking over seven minutes for one test to run. Ridiculous.

So I took a step back and asked what is the original problem. What do I the human tester actually need and do when manually testing one of these reports?

I decided to set formatting aside. Important, but for my particular needs I could indeed relegate that to other tests or even to manual testing.  The most important thing for me was to test the content of the Crystal report output to make sure what was coming from the database was correct. The other important thing was to run the multiple data exports, which manually involved clicking buttons, waiting, clicking more buttons, dozens of times over.

So the answer so far is to divide, focus, and conquer.

I put the button pushing into entirely separate tests. Now I can just run those UI tests and the machine does all the button pushing for me while I do something that really requires the attention of an actual person.

Back to the content: I just want to make sure the content is correct.

Remember how in your mapWhatever.cs code you've got lines of code that look like

     var something = rpt.UIWEbblahbalh.UIBobjidyaddayadda.somethingsomethingFrame...InnerText

?

That's called threading. Threading is what is going to kill your efficiency with this tool and with theses tests. Threading takes a looong time for some reason. YOU ONLY WANT TO THREAD ONCE IF YOU CAN HELP IT. My problem was I was threading multiple times, slowing my test way down.

So I just figured out how to thread once and get all the content of the report into a single long string (this will vary depending on how your page was built). Then, for the assertion I did StringAssert.Contains(<bigString>, <smallString>)

<bigString> is the big long string of content.

<smallString> is the value I need to make sure appears in the content.

Test takes less than two minutes now. Still slow, but in the acceptable range, because I have to do this same test dozens of time every time we update and have to do general regression testing. Better to have the machine do it.

No comments:

Post a Comment