문제

We use n-layer architecture in our application. Suppose we use 3 layer application and use MVC pattern for Presentation Layer,Which Layer should test? How can find testability point in my application?

  1. Presentation Layer?
  2. Business Layer
  3. Data Layer
  4. All of them?
도움이 되었습니까?

해결책

Only test the layers you want to be sure work. All 3 of the above seem to be things it would be important to have working. You wouldn't want to remove any of them.

Trying to find testability points in existing software where it hasn't been designed for can be a challenge. There's a good book, Working Effectively with Legacy Code, where legacy is defined as code without tests, that talks about this issue. Basically, if you don't design for testability, it's can be hard to shoe-horn it in, you'll probably need to refactor.

The trick is going to be adding test infrastructure to the code: mocks, stubs, and other test components to allow you to isolate just the bits under test. This is helpful when you test a DB, you really don't want to run a real query, it'll just take too long and you want the tests to be FAST. Dependency Injection can be helpful for the more static languages, like C++/C and Java.

다른 팁

What is a "unit", in the context of unit-testing? It is whatever you identify as a unit, as the smallest testable part of your code.

These days, most people choose the class or method as their unit. If you do the same, all your layers will contain units that you can unit test, so the answer to you question is to test all of them.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top