High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 2

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 2

This is the third article from the new series- High-Quality Automated Tests. In the first publication, I showed you how to apply coding standards and styles in your .NET tests using EditorConfig. This is the second part of the list of the coding styles you need to use. If you haven’t read the first part, I suggest doing so.

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.

11. Style Expression Bodied Properties

CORRECT

// csharp_style_expression_bodied_properties = true:error
public int PlanetsCount => 42;

INCORRECT

// csharp_style_expression_bodied_properties = false:error
public int MoonsCount
{
    get { return 13; }
}

12. Style Throw Expression

CORRECT

// csharp_style_throw_expression = true:error
FuelType = fuelType ?? throw new ArgumentNullException(nameof(FuelType));

INCORRECT

// csharp_style_throw_expression = false:error
if (fuelType == null)
{
    throw new ArgumentNullException(nameof(fuelType));
}
this.FuelType = fuelType;

13. Style var Elsewhere

CORRECT

// csharp_style_var_elsewhere = true:error
int moonSize = CalculateMoonSize();

INCORRECT

// csharp_style_var_elsewhere = false:error
var secondMoonSize = CalculateMoonSize();

14. Style var for Built in Types

CORRECT

// csharp_style_var_for_built_in_types = true:error
var planetSize = 42;

INCORRECT

// csharp_style_var_for_built_in_types = false:error
int secondPlanetSize = 42;

15. Style var When Type Is Apparent

CORRECT

// csharp_style_var_when_type_is_apparent = true:error
var robots = new List<int>();

INCORRECT

// csharp_style_var_when_type_is_apparent = false:error
List<int> robots = new List<int>();

16. Sort System Directives First

CORRECT

// dotnet_sort_system_directives_first = true
using System;
using System.Collections.Generic;

INCORRECT

// dotnet_sort_system_directives_first = false
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;

17. Style Coalesce Expression

CORRECT

// dotnet_style_coalesce_expression = true:error
int? sunSize = null;
var blackHole = sunSize ?? 10000;

INCORRECT

// dotnet_style_coalesce_expression = false:error
var secondBlackHole = sunSize != null ? sunSize : 10000;

18. Style Collection Initializer

CORRECT

// dotnet_style_collection_initializer = true:error
var shieldsPower = new List<int> { 42, 13 };

INCORRECT

// dotnet_style_collection_initializer = false:error
var shieldsPower = new List<int>();
shieldsPower.Add(42);
shieldsPower.Add(13);

19. Style null Propagation

CORRECT

// dotnet_style_null_propagation = true:error
var smallSpaceShip = spaceShipFactory?.Build();

INCORRECT

// dotnet_style_null_propagation = false:error
var smallSpaceShip = spaceShipFactory == null ? null : spaceShipFactory.Build();

20. Style Object Initializer

CORRECT

// dotnet_style_object_initializer = true:error
var bigSpaceShip = new SpaceShip
{
    Name = "Meissa"
};

INCORRECT

// dotnet_style_object_initializer = false:error
var bigSpaceShip = new SpaceShip();
bigSpaceShip.Name = "Meissa";

Summary

I presented to you 20 of my favorites EditorConfig coding styles. In the next articles of the series, I will show you another tool for coding standards called StyleCop. I will again share my must-use rules in a couple of articles.

Related Articles

High-Quality Automated Tests

High-Quality Code- Naming Methods

In the last articles from the High-Quality Automated Tests we talked about coding styles and various tools that can help you to force them automatically. In thi

High-Quality Code- Naming Methods

High-Quality Automated Tests

High-Quality Code- Naming Classes, Interfaces, Enumerations

In the last articles from the High-Quality Automated Tests we talked about coding styles and various tools that can help you to force them automatically. In thi

High-Quality Code- Naming Classes, Interfaces, Enumerations

High-Quality Automated Tests

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 1

This is the second article from the new series- High-Quality Automated Tests. In the previous publication, I showed you how to apply coding standards and styles

High-Quality Automated Tests- Top 10 EditorConfig Coding Styles Part 1

High-Quality Automated Tests

Testing for Developers- Isolation Frameworks Fundamentals

In the series we will define the basic terms that every developer needs to know about testing. The purpose is to give all team members a shared understanding of

Testing for Developers- Isolation Frameworks Fundamentals

High-Quality Automated Tests

Testing for Developers- Unit Testing Fundamentals

In the series we will define the basic terms that every developer needs to know about testing. The purpose is to give all team members a shared understanding of

Testing for Developers- Unit Testing Fundamentals

High-Quality Automated Tests

High-Quality Automated Tests- Consistent Coding Styles Using EditorConfig

This is the first article from a new series of posts called- High-Quality Automated Tests. I firmly believe that all coded tests should be treated with respect

High-Quality Automated Tests- Consistent Coding Styles Using EditorConfig
Anton Angelov

About the author

Anton Angelov is Managing Director, Co-Founder, and Chief Test Automation Architect at Automate The Planet — a boutique consulting firm specializing in AI-augmented test automation strategy, implementation, and enablement. He is the creator of BELLATRIX, a cross-platform framework for web, mobile, desktop, and API testing, and the author of 8 bestselling books on test automation. A speaker at 60+ international conferences and researcher in AI-driven testing and LLM-based automation, he has been recognized as QA of the Decade and Webit Changemaker 2025.