Test Development Philosophy

I am currently going through http://www.railstutorial.org/

It uses Rspec along with the TDD approach. I understand that writing a lot of tests can help you avoid mistakes as your application becomes more complex, but I don’t understand why you write tests for simple things like having a page name. It seems that you end up writing as many tests as the actual code.

Is it better in the long run, or is it too complicated?

+3
source share
7 answers

It seems you have finished writing as many tests as the actual code.

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

, , . , , ( ).

+8

"Test Driven Design" -

, , , , TDD - , , , .

AgileData.org , :

TDD - , . , , .

, .

, , , , . , (, , ) , , .

+3

, N 2 , . , , , , .

:

if (@user.posts.count > @limit.posts)
  # Branch 1
  flash.now[:error] = "You have posted too many times today."
elsif (@user.suspended?)
  # Branch 2
  flash.now[:error] = "Your account is suspended. You cannot post."
else
  if (@post.special? and !@user.can.post_special?)
    # Branch 3
    flash[:warning] = "You cannot create special posts."
    @post.special = false
  # else
    # Branch 4
    # Not branching also has to be tested
  end

  if (@user.recently_created?)
    # Branch 5
    @post.newbie = true
  # else
    # Branch 6
  end

  # Branch 7
end

unless (flash[:error])
  @post.save!
end

, , , . , . , , factory , , .

- . , , , , , , , .

, , -, , , -. , - .

-, , , .

+3

, UI. , , , (, ) .

MVC, ui , .

, !! , !

+2

It seems that you end up writing as many tests as actual code

.

+2

, , TDD. , - ", ". , , , , , , .

, , , . , , TDD BDD. , , , . , , TDD, .

+2

TDD , . , , , , , , .

, , , , , , , .

, . , .

Throughout the product life cycle , it’s easier to do maintenance work because your test suite will quickly tell you that changes to the code didn’t break anything.

+2
source

Source: https://habr.com/ru/post/1756017/


All Articles