0

I want to write a customized HTML report for my sanity test automation. So, this is what I have in my mind:

  1. Create a Singleton Class (Jon Skeet's version of a thread safe Singleton with fully lazy instantiation in C#)
  2. Create a method to create a HTML file inside the constructor (So the HTML file is created only once when the single constructor is called)
  3. Through out my code, I can call the HTML write() or append() method to write data into my HTML file

Do you see any problem with my logic? If it is so naive and a bad practice, can you please point me to some examples that write HTML reports in C# so I can adapt it in my project?

Thank you!

EDIT

So, when i say custom reporting this is what I am thinking...

A MasterIndex.HTML - that will have a list of all scenarios I have run. Each of the item in this list are clickable. Multiple detailed HTML reports - When I click on each of the items/scenarios on my MasterIndex file, it will take me to another html with the steps I have done to execute that test scenario with Pass/Fail.

Bhavani Kannan
  • 1,269
  • 10
  • 29
  • 46
  • you need to get answers to couple of question ,you wish to create multiple files for each detailed report?is creating a file logic in constructor a good idea then, Is the need to make code fancy or performant(buffer Queue to write at once) / ThreadSafe ? why you need singleton ? .Threadsafety can easily be achieved in multiple ways (TPL, locking), – Abdul Khan Jun 21 '16 at 06:18
  • Okay, your questions make sense. I read some online articles and my mind went along with the singleton but other than that there is no real need for restricting myself with singleton classes. Given that, can you show some code samples to get started? Should I be writing the tags too? Or are there any template engines already out there? Thank you! – Bhavani Kannan Jun 21 '16 at 06:21
  • @Bahavani are you using selenium ? or what framework for automation – Abdul Khan Jun 21 '16 at 06:42
  • It's a custom data driven framework in c# and the tool we use is MS VS CodedUI. Thank you! – Bhavani Kannan Jun 21 '16 at 06:51

1 Answers1

1

Knowing that i will use a pattern initially before any thing may not be a good idea as Patterns Are Not Goals, They Are Tools.

Based on my understanding,I would start it with a (Kiss)simple design and let my Report generator at least work the basic intended functionality,thereafter make that framework more kind of generic with additional features and in path making the design more flexible and configurable.To get started you may refer following Links:

html reporting

create html-report without hard coded html

writing to file in a thread-safe manner

*Note : While creating your own utility do keenly look for hard coding,boilerplate code and coupling also find possible methods/design pattern to overcome those and in no time you could come up with a clean sweet utility.

Community
  • 1
  • 1
Abdul Khan
  • 363
  • 3
  • 13