Archive

Posts Tagged ‘Testing’

Full Test Coverage is Impractical

May 22nd, 2013 7 comments

Many developers claim that to achieve high quality software, developers must create automated tests that ensure that all possible execution routes have been covered. This is also known as full path coverage. I will argue that different types of software require different testing approaches and that full path coverage is impractical in almost every case. Too many tests simply create clutter. Read more…

Tags: , ,

Define: Functional, Unit and Integration Tests

April 5th, 2013 7 comments

I have recently read a blog post claiming that functional tests are not “true” tests. The author also claims that unit testing shows you where the problem is occurring, while functional testing simply identifies that a problem exists. This argument is deceptive and the conclusion dangerous. Different kinds of tests are not mutually exclusive. One is not superior to the other. They have different goals and can happily coexist. Let me explain the kinds of tests so that you could make enlightened decisions.

Read more…

Tags: , ,

You Don’t Become a TDD Expert Overnight

March 27th, 2013 1 comment

Do you want to write unit tests but don’t know where to begin? Don’t panic and follow these steps to ease into the testing business. Practice testing often to achieve best results.

Tip: try to test the smallest unit possible, usually a function, rather than a combination of functions. Testing combinations is called integration testing, which I will cover in subsequent posts.

Here are a few easy to spot opportunities for writing unit tests.

Read more…

Tags: , ,

Selenium 2: Wrong Browser Launched

June 20th, 2012 No comments

I have a test suite with PHPUnit and Selenium. I recently upgraded to Selenium 2 (Selenium WebDriver) and updated my PHP code. I specified explicitly in my code that Firefox should be used but the tests consistently opened Chrome instead.

The error did not come from the fact that I incorrectly updated my code. You see, with Selenium 1 test cases, browsers were defined like this: *firefox. With Selenium 2, you have to drop the asterisk like this: firefox. Otherwise, your system’s default browser will be used.

That’s it. Happy testing!

Tags: ,

10 Reasons to Write Unit Tests

May 31st, 2010 9 comments

It’s been bothering me for quite some time not being able to explain the people out there why they need to write unit tests. The most common responses that I got were “this is a waste of time” and “my application has no bugs”. Unfortunately, this overconfidence and cutting corners is hurting the developers (and the industry).

I compiled this short list of why I write unit tests:

  1. Don’t let your customers discover embarassing bugs. Write tests to cover a multitude of scenarios and catch these bugs before they get into production.
  2. Test complex scenarios quickly, without having to manually reproduce them in the application.
  3. By testing often, you don’t break the application as you go. You can’t always know the indirect implications of what you’re writing, especially if you didn’t write the original application.
  4. By testing early, you don’t write unnecessary code but only the strict necessary. This makes the codebase smaller and more maintainable. It also saves on development time.
  5. You do not have to debug the same code twice. Once you have a test to account for a possible bug, you’ll pick up any wrong turns quickly.
  6. You ensure readability. A unit test makes the purpose of your code easier to understand.
  7. You ensure maintainability. Unit-testing forces you to better encapsulate functionality, thus making it easier to maintain and add new features.
  8. Refactor without worries. Run the tests to make sure everything still functions as intended.
  9. Save time on testing. You can test the entire application at the speed of your CPU.
  10. Feel safer. How many times were you afraid to add a new feature or change something in your application’s core? No more!
  11. Bonus: know exactly what is broken. Instead of hunting for an obscure bug, let the tests tell you what’s wrong and why. Example: the application will tell you when you add an item to a cart but the cart still appears empty. It will also tell you what item you tried to add for the cart to break.

You may have different reasons, so share them in your comments.

Tags: