Test Driven Development in PHP

前端 未结 8 1828
青春惊慌失措
青春惊慌失措 2021-01-29 23:47

I am a web-developer working in PHP. I have some limited experience with using Test Driven Development in C# desktop applications. In that case we used nUnit for the unit testin

相关标签:
8条回答
  • 2021-01-29 23:59

    I've used both PHPUnit & SimpleTest and I found SimpleTest to be easier to use.

    As far as TDD goes, I haven't had much luck with it in the purest sense. I think that's mainly a time/discipline issue on my part though.

    Adding tests after the fact has been somewhat useful but my favorite things to do is use write SimpleTest tests that test for specific bugs that I have to fix. That makes it very easy to verify that things are actually fixed and stay fixed.

    0 讨论(0)
  • 2021-01-30 00:07

    Test driven development is an approach where tests are always written before code. You should learn to PHPUNIT first in order to start TDD Development. Then while making your function you should always think how function can fail and write test case in phpunit and in the end you should write code in order to pass your test. Its will be a new approach so it will be little difficult in the beginning but once you get use to it, you will find it very useful specially for after development bugs and coding style. You can go through this Step By Step guide for understanding this concept.

    Always Remember if test are written after development they are useless. So TDD is must if you are thinking to write unit tesst

    0 讨论(0)
  • 2021-01-30 00:09

    You should look into PHPUnit, it looks pretty much like nUnit.

    0 讨论(0)
  • 2021-01-30 00:15

    PHPUnit is a standard, but it's sometimes also overwhelming, so if you find it too complex, check out phpt to get you started. It's very, very easy to write tests in it. A no brainer for any programmer.

    And to answer your TDD question - I am not sure if TDD is widley used in the PHP space. I can see that rapid application development and TDD somewhat clash (strictly IMHO). TDD requires you to have the complete picture of what you build and you write your tests up front and then implement the code to make the test pass.

    So for example what we do instead, is to write a lot of tests when we are done. This is not always the best approach because you sometimes end up with bogus tests that pass, but are not really useful but at least it's something you can expand on. Internally we continue on tests and basically write a test for each bug we find. This is how it becomes more solid.

    0 讨论(0)
  • 2021-01-30 00:16

    I highly recommend Test-Driven Development by Kent Beck (ISBN-10: 0321146530). It wasn't written specifically for PHP, but the concepts are there and should be easily translatable to PHP.

    0 讨论(0)
  • 2021-01-30 00:21

    Another modern tool you should look it is Codeception. It is much simplier then PHPUnit and incorporates scenario-driven approach, which is quite useful for generating documentation from tests.

    0 讨论(0)
提交回复
热议问题