What are the benefits of self-testing code and individual tests?

Personally, I always put unit tests in a separate project just because, like MSTest, it seems to be configured. But I read Martin Fowler's Refactoring: Improving the Design of Existing Code, and he seems to advocate not only putting them in one project, but putting them in the same class as the method they are testing.

I really honestly don’t understand how this differs from the fact that tests are in a separate area from the code itself, except for philosophical differences (is it test documentation or a mess?).

Are there clear reasons to choose one by one? Or is it basically a philosophical difference?

UPDATE . I'm not necessarily convinced anyway, but at least I have an idea of ​​what arguments are. I'm sorry that I can’t choose all, but I only had to choose one.

+5
source share
7 answers

There may be some kind of elegance for the self-test code, but I am inclined to adhere to the same philosophy as you - that code separation is superior to the concept of abstract beauty. When you create a class, you can fundamentally split it into three parts:

  • What a class does (e.g. class definition)
  • How does this happen (implementation)
  • How do you use it (documentation and / or test cases)

, . , , , , , . , , .., , .

, , .

+5

, NUnit , .

, , , NUnit.Framework.dll, , Rhino.Mocks.dll.

.

, .

+4

(, , ) , .

+3

, , . ( TDD) Main , , . , . , , , . .

, TDD / . , /. "test" (a.k.a "design" ) . "" / .

, " unit test " " " " ", . , -.

+2

. :

  • . 100 200 . ( TDD .)

  • . 1:1. 1:1 .

http://blog.daveastels.com/files/BDD_Intro.pdf

" , , , . Test . ( 1-1) ".

Java Maven . , , , (/src/main/java /src/test/java). Maven , , .


: 10 (2019)

Clojure, . . ( .) Clojure , . clojure.test , clojure.test .

-, , . , , - , - . - .

: , . , , , . TDD, . Kata , , , .

+2

.

( ), , , .

, Refactoring ( ), , , .

+1

, .

- , , , , . , . , (), "" (, "", "" , ).

, , , , . - , //, , , , , , .

. "", , , , / . - , , , , , " " .

, , . , , , , , , . , .

TDD - , , , , . , . , ( ) , , .

. . , , . , , - , , , . , , . , . , , , . , , . , . , .

. , , , - .

, . , .

, . , , , /, , . , , , , . , / , . "" , "", . - ( - , - - , - , - ), , , ( ). , , , , , , , ? , ( - API. , , , , .

0
source

All Articles