News Feed

News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Jani Hartikainen:
What's the difference between Unit Testing, TDD and BDD?
March 02, 2015 @ 09:16:28

On his site today Jani Hartikainen has a new post helping to demystify some potential confusion around unit testing, test-driven development and behavior-driven development. He's talking about them in the context of Javascript in this case, but the fundamentals transfer to just about any other language, including PHP.

When you're just getting started with automating your JavaScript testing, there's a lot of questions. You'll probably see people talk about unit testing, TDD or Test-Driven Development, and BDD or Behavior-Driven Development. But which one of them is the best approach? Can you use all of them? I've talked to a number of JavaScript developers, and there seems to be some confusion about all this. So, let's take a look at Unit testing, TDD and BDD, and fix some of the common misconceptions about them out there.

For each he provides an overview of this basic concepts and a bit of sample code showing it in action. For TDD (test-driven development) there's not really a way to show it specifically in code as it's more of a practice. Instead he gives a "checklist" to follow when practicing it.

Unit Testing gives you the what. Test-Driven Development gives you the when. Behavior Driven-Development gives you the how. Although you can use each individually, you should combine them for best results as they complement each other very nicely.
0 comments voice your opinion now!
bdd unittest tdd testdrive behaviordriven development introduction


SitePoint PHP Blog:
Basic TDD in Your New PHP Package
January 28, 2015 @ 12:27:17

The SitePoint PHP blog continues their "How to Build Your Own PHP Package" series with their latest post (part two of the series) covering the use of test-driven development while working on the package code.

In part 1, we set up our development environment, baked in some rules as inherited from The League, and created two sample but useless classes - Diffbot and DiffbotException. In this part, we'll get started with Test Driven Development.

He starts by briefly introducing PHPUnit, a PHP-based unit testing tool, and how to use it to generate the HTML version of the code coverage report. He helps you define a good phpunit.xml configuration file and how to execute a first sample test (code provided) from inside PHPStorm. From there he adds one some more complex testing of exception handling and checking the class types. With this foundation, he moves into the test-driven development (TDD) practices. TDD means writing the tests before writing the code to make those tests pass. He gives an example of this and shows how test abstract classes too. He then comes back around and writes the code to satisfy the test.

0 comments voice your opinion now!
tdd package bestpractice unittest testdriven development tutorial


Mathias Verraes:
How Much Testing is Too Much?
January 02, 2015 @ 11:55:43

In his latest post Mathias Verraes poses the question of how much testing is too much? At what point does testing actually become less useful and how much you really need.

Figuring out how much unit tests you need to write, can be tricky, especially if you are new to Test-Driven Development. Some teams strive for 100% code coverage. Some open source projects even announce their test coverage on their GitHub profiles - as if coverage is an indicator of quality. Coverage only measures the lines of code that are executed by the test suite. It doesn't tell you whether the outcome of the execution is actually tested, let alone how valuable that test is. Because of that, code coverage of your entire code base is a pretty lousy metric.

He suggests that the "it depends" answer to "how much testing is enough" question just isn't good enough. He puts most of this in the context of TDD (where testing is built-in to the development time) but some of the thoughts could apply to post-code testing as well. He also talks about over-design and how it relates to refactoring with deeper insight. Finally, he talks about a subject not mentioned much in testing articles - when to delete tests.

0 comments voice your opinion now!
unittest testdrivendevelopment tdd too much overdesign refactor delete

Understanding PhpSpec
September 04, 2014 @ 11:09:42

The site (well, TutsPlus) has posted a new tutorial that gets you more intimate with PhpSpec, a PHP-based testing tool that lets you define tests as specifications and using behavior-driven development principles. If you need an introduction to the tool, check out this other tutorial first.

If you compare PhpSpec to other testing frameworks, you will find that it is a very sophisticated and opinionated tool. One of the reasons for this, is that PhpSpec is not a testing framework like the ones you already know. Instead, it is a design tool that helps describing behavior of software. A side effect of describing the behavior of software with PhpSpec, is that you will end up with specs that will also serve as tests afterwards. In this article, we will take a look under the hood of PhpSpec and try to gain a deeper understanding of how it works and how to use it.

They provide a quick overview of some of the internals of the PhpSpec tool and a brief look at the difference between BDD (behavior-driven) and TDD (test-driven) development practices. There's also a look at how the tool differs from the popular PHP testing tool PHPUnit. Code examples are provided through out the post with simple tests, making the separation between the methods and tools easier to follow.

0 comments voice your opinion now!
tutorial phpspec testing tool bdd tdd unittest behaviordriven development


Matthias Noback:
The PHP testing experience Interview by Fernando Arconada
July 15, 2014 @ 09:54:12

Matthias Noback has a new post today, an interview that was conducted with him by Fernando Arconda about his experience and thoughts around testing in PHP-driven applications.

Fernando Arconada interviewed me about the subject of testing. He is writing a book about testing Symfony2 applications: Testing para Aplicaciones Symfony2. Fernando will translate this interview to Spanish and and add it to his book, together with the articles in my A better PHP testing experience series.

The interview starts with some background on who Matthias is and what kinds of things he's done in the past with BDD and TDD testing. He answers questions about testing, even for small projects, and if the sought after "100% coverage" is a good mark to try for. They discuss tooling and include some recommendations to beginner developers to help them get testing quickly. A large part of the interview also shares some of his thoughts around the "BDD/TDD is dead" debate that happened not too long ago.

0 comments voice your opinion now!
interview fernandoarconda testing bdd tdd unittest

Lately in PHP Podcast #48 - To TDD or Not TDD?
June 27, 2014 @ 11:38:37

On the site today Manuel Lemos has released the latest episode in their "Lately in PHP" podcast series: Episode #48 - To TDD or Not TDD?.

Lately the debate about whether you should use TDD or not in all software projects all the time has been very intense. [...] They also talked about the upcoming end of life release of PHP 5.3, getting information of parameter type hinting with reflection, using object methods on native data types, security problems of OAuth implementations, and the built-in support of Composer to access password protected repositories.

You can listen to this latest episode either through the in-page audio player, by downloading the mp3 or you can watch the live recording over on the PHPClasses YouTube playlist. A transcription of the recording is also provided as well as links to some of the topics mentioned.

0 comments voice your opinion now!
phpclasses latelyinphp ep48 podcast tdd typehint oauth security composer


Inviqa Blog:
How clean is your code?
June 13, 2014 @ 10:55:44

In this latest post to the Inviqa blog they ask the question "how clean is your code?" and offer a few tips to help it get that way (and stay that way).

During the Test Driven Development training (which includes Behat, and PHPspec) run by Marcello Duarte, I was particularly blown away by one of his many and funny analogies… "Would you have any surgery carried out by a doctor who does not wash his hands?" Everybody in the room shook their heads. Of course nobody would. There is too a high risk of complications. In software development 'infected' code can translate to bugs, bad user experience, poor performance and the complete failure of web applications.

He talks briefly about some of the lessons learned in this training session, pointing out that while it's not the easiest method to apply, it pays off in the long run of your code's "hygiene". He points out that the [Inviqa] group's success rate with TDD/BDD has reflected in the bottom line of their enterprise clients too.

0 comments voice your opinion now!
testdrivendevelopment tdd code hygiene training bdd

7 Reasons Why TDD Failed to become Mainstream
June 11, 2014 @ 09:44:39

In the latest post Manuel Lemos suggests severn reasons why TDD failed to become mainstream in most development communities. This is related to comments from an leader in another community about his perspective on the "TDD movement".

Recently the creator of Ruby On Rails declared that TDD (Test Driven Development) is dead. Despite he used to be a supporter of TDD as the right way to do software development, he finally decided to announce that he really does not agree that TDD is really the right way. Read this article to learn more about what happened and what does this mean for developers that support TDD or not.

He starts with a brief look at what TDD (test-driven development) is and a link to a ThoughtWorks video of DHH talking about his new stance. Among his reasons are things like:

  • TDD is Expensive
  • You Will Change Your Projects and Old Tests Become Waste
  • Extensive Testing is Boring
  • Many TDD Preachers Do Not Use it Most of the Time But Do Not Admit it

Manuel shares some of his own opinions on the matter, though, pointing out that he doesn't think TDD is dead. He suggests that it helps to "make you rethink" when developing and that your (and your development group's) practices shouldn't be influenced by outside opinions - use what works.

0 comments voice your opinion now!
tdd fail mainstream opinion dhh video introduction


Federico Cargnelutti:
TDD Checking the return value of a Stub
April 16, 2014 @ 10:25:15

Federico Cargnelutti has a helpful post to his site today for the unit testing/TDD crowd about checking the retuned value from a stub of an object in your tests. He's using the built-in mocking framework here, not something like Mockery.

State verification is used to ensure that after a method is run, the returned value of the SUT is as expected. Of course, you may need to use Stubs on a test double or a real object to tell the object to return a value in response to a given message. [...] In PHP, for example, you dynamically type the return value within the body of the method. This means that PHP mocking libraries cannot check the type of the return value and provide guarantees about what is being verified. This leads to the awkward situation where a refactoring may change the SUT behaviour and leave a stub broken but with passing tests.

He gives an example of a few classes - a Presenter and Collaborator - and a test that mocks out the Collaborator instance, calling a "getStories" method on it. He shows a situation where all tests pass in the initial version, but after some changes to the return type, a test that should fail doesn't. His solution for the issue revolves around DocBlock annotations and the Return Value instead of the built-in mock object return method.

0 comments voice your opinion now!
tdd unittest return value stub passing test returnvalue mock


Francesco Tassi:
Switching From TDD to BDD With Behat and Symfony2
August 16, 2013 @ 13:27:32

In this new post to his site Francesco Tassi shares his experience making the switch from doing just test-driven development on his Symfony2-based applications to behavior-driven development using Behat, Mink and PHPSpec.

Recently I started a small extra project with a smart fellow from my local PHP User Group, since the project was quite simple and both of us were willing to learn something new, we decided to give BDD a try. In the PHP world BDD means Behat, Mink and PHPSpec. [...] In this post I won't cover all the details about BDD, Behat or PHPSpec, I'd rather describe how I switched from PHPUnit and TDD to BDD (and also show some bits of code).

He talks about the switch in mindset that comes along with adopting BDD and how you think about testing - not what it does, but what it should do. He talks some about test organization, configuration and his process for executing them. There's a bit about working with databases (with fixtures and @BeforeScenario) including the code for the feature file to make it happen.

0 comments voice your opinion now!
tdd testdriven bdd behaviordriven behat symfony2 tutorial


Community Events

Don't see your event here?
Let us know!

unittest extension library language opinion wordpress development podcast series community introduction framework release interview psr7 conference laravel5 laravel api voicesoftheelephpant

All content copyright, 2015 :: - Powered by the Solar PHP Framework