samedi 25 juin 2016

Unit testing Application design, Design Pattern, Best Practices

In general mostly I write unit test for testing the functionality of the application/methods. In my recent reading, I've come across concept of Unit testing the "Loose Coupling" of the application components. I noticed a Unit test written to check the reference of unexpected assemblies (e.g Presentation layer directly referring DataAccess Classes instead of Business Logic classes), This unit test will immediately fail if it encounters the unexpected references that breaks "loosely coupled" design.

I like this concept of writing unit testing to test the best practice/design of the application. Just want to see if there are any pointers/resources which will help us write Unit test to test the application design/architecture.

Please share if you know anything more about this area.

This is the sample code.

[Fact]
public void SutShouldNotReferenceSqlDataAccess()
{
// Fixture setup
Type sutRepresentative = typeof(HomeController);
var unwanted = "Ploeh.Samples.Commerce.Data.Sql";
// Exercise system
var references =
sutRepresentative.Assembly
.GetReferencedAssemblies();
// Verify outcome
Assert.False(
references.Any(a => a.Name == unwanted),
string.Format(
"{0} should not be referenced by SUT",
unwanted));
// Teardown
}

Aucun commentaire:

Enregistrer un commentaire