vendredi 20 octobre 2017

NUnit assertions in production code

I am trying to find best practices for having assertions in production code but I am surprised at how little information I have found.

First is it generally acceptable or not to have assert statements in production code?

Second I read that the built in Debug.Assert for .NET essentially automatically disables itself for production code and only actually runs in development environments. Is that true and does NUnit also have this functionality built in?

For example if I have the following in production code would the assertion be ignored?

var sortedActuals = actuals.OrderByDescending(a =>
                    {
                        Assert.That(a.GLPeriodDateTime, Is.Not.Null, "GLPeriodDateTime was null when it should not be");
                        return a.GLPeriodDateTime.Value;
                    })

Aucun commentaire:

Enregistrer un commentaire