This is the new article from the High-Quality Automated Tests series. In the last publication, I showed you how to apply coding standards and styles in you .NET tests using StyleCop. In this one, I am going to share with you some of the coding styles that you need to use. Initially, my idea was to publish all of them in a single post, but since there are a lot, I decided to split them into three parts.

While ago when we were working on the first version of the BELLATRIX test automation framework, I did this research while I was working on a similar feature for our solution.

1. SA1519 Braces Must Not Be Omitted from Multi-line Child Statements

CORRECT

INCORRECT

“Although this is legal in C#, StyleCop requires the braces to be present when the statement spans multiple lines, to increase the readability and maintainability of the code.”

Since this is like a religious war between different programmers. I did additional research. Below you can find most up-voted answers in the most popular programming forums and groups.

2. SA1515 Single Line Comment Must Be Preceded by Blank Line

CORRECT

“To improve the readability of the code, StyleCop requires blank lines in certain situations, and prohibits blank lines in other situations. This results in a consistent visual pattern across the code, which can improve recognition and readability of unfamiliar code.”

INCORRECT

3. SA1513 Closing Brace Must be Followed by Blank Line

CORRECT

INCORRECT

4. SA1507 Code Must Not Contain Multiple Blank Lines in a Row

CORRECT

INCORRECT

"To improve the readability of the code, StyleCop requires blank lines in certain situations, and prohibits blank lines in other situations. This results in a consistent visual pattern across the code, which can improve recognition and readability of unfamiliar code."

5. SA1502 Element Must Not Be On Single Line

CORRECT

INCORRECT

6. SA1500 Braces for Multi Line Statements Must Not Share Line

CORRECT

INCORRECT

7. SA1627 Documentation Text Must Not Be Empty

INCORRECT

8. SA1005 Single Line Comments Must Begin with Single Space

CORRECT

INCORRECT

9. SA1204 Static Elements Must Appear Before Instance Elements

CORRECT

INCORRECT

Summary