Лучшие практики разработки через тестирование с использованием C # и RhinoMocks [закрыто]

Чтобы помочь моей команде в написании тестируемого кода, я разработал простой список рекомендаций, которые помогут сделать нашу кодовую базу C # более тестируемой. (Некоторые из пунктов относятся к ограничениям Rhino Mocks, фальшивой среды для C #, но правила могут также применяться и в более общем плане.) Есть ли у кого-нибудь лучшие практики, которым они следуют?

Чтобы максимизировать тестируемость кода, следуйте этим правилам:

Write the test first, then the code. Reason: This ensures that you write testable code and that every line of code gets tests written for it.

Design classes using dependency injection. Reason: You cannot mock or test what cannot be seen.

Separate UI code from its behavior using Model-View-Controller or Model-View-Presenter. Reason: Allows the business logic to be tested while the parts that can't be tested (the UI) is minimized.

Do not write static methods or classes. Reason: Static methods are difficult or impossible to isolate and Rhino Mocks is unable to mock them.

Program off interfaces, not classes. Reason: Using interfaces clarifies the relationships between objects. An interface should define a service that an object needs from its environment. Also, interfaces can be easily mocked using Rhino Mocks and other mocking frameworks.

Isolate external dependencies. Reason: Unresolved external dependencies cannot be tested.

Mark as virtual the methods you intend to mock. Reason: Rhino Mocks is unable to mock non-virtual methods.

Ответы на вопрос(7)

Ваш ответ на вопрос