Apr
10

What Is Test Driven Development

Time to go basic again. Let’s talk about TDD.

Test Driven Development has been practiced for a while. One of the practices in Extreme Programming was Test-First (more than a decade ago):

Code the unit test first.

Sounds simple enough, but there’s a whole process around it. Here’s a nice picture to explain it:

image

Here’s the recipe: Write a failing test, write the code that makes it pass and refactor.

What makes TDD so important that it was a core part of XP? Quite literally it changes the way you code.

Think about how you do it today: You need to add a feature. So you jump right into the code, hacking what’s needed, taking the necessary risks and you have a (more ore less, usually less) working feature.

But with TDD you introduce a disciplined incremental process that has built-in feedback into it. That’s how you write quality software.

You start with a small, focused test. Usually, it’s around a class, or even a method. For example, here’s a first test for a Mailbox object (that doesn’t exist yet):

[TestMethod
public void MessageCount_EmptyMailbox_Zero()  
{
      Mailbox mailbox = new Mailbox();      
      Assert.AreEqual(0, mailbox.MessageCount);
}

Let’s see what we have in our very short test:

  • A name that describes a scenario of how the object is used
  • A name for the object – that other programmers can understand. With a proper name, you convey expectations.
  • Method of creating of the object – a simple constructor. It doesn’t need dependencies (at this point)
  • Default behavior of object – returning zero on an empty.

With writing the test first, we actually describe the object to others, in terms of interface and behavior. Working this into a process, we’re adding more functionality incrementally, in small doses, and we know all the time that what we’ve coded before still works.

Unit tests give you a safety net around your code, so if you break something, you’ll know immediately. TDD is taking this further, wrapping the entire code with the safety net. Just follow the simple procedure above!

Well, it may seem simple, but still, most people don’t do TDD. There are a whole lot of bumps in the road that you should be aware of starting out.

Ah, If there was somewhere to go and learn this stuff…

Wait, there is!

Join me in my “Introduction to TDD” webinar next week, and learn more. We’ll talk about do’s and don’ts, benefits and pot-holes, and code a few simple and real-life samples.

Register now!

Permanent link to this article: http://www.typemock.com/blog/2012/04/10/what-is-test-driven-development/

Apr
05

The Difference Between Automated and Manual Testing

crash test dummies

It may seem that the answer is quite clear. With manual testing, you need a person. For automated processes, you need a person to press a button, if at all.

But there’s more than that.

In a former life, I managed a software project where I had both testers and developers. In the application we developed, there was a database schema that changed all the time (it was at a stage prior to release). Every new build, the testers ran a manual upgrade test, checking that data in the old version database could be upgraded to the new version. This procedure was manual and took about a day for  a single tester. And we were releasing 2-3 times a week.

Of course this could have been automated, but I was much younger then, and didn’t know any better. I was under the impression that that’s just the way it is, and that automating is too much trouble. In fact, I also believed that tester’s time is cheaper than developer time, so software economics were in favor of staying this way. At least I know better now.

Automation requires time and maintenance. But it frees us to do what we’re good at: develop more features, or exploratory testing. Manual testing means we’re sacrificing time and effort, instead of letting a computer do it, with the same results. Software economics, like regular economics requires us to automate.

There’s another problem with manual testing: Our applications are so complex, so wasting time manual testing, means we forsake all hope of testing the entire application. Therefore, we we compromise the quality of our product  because of our belief: “that’s just the way it is”. Our time, developers and testers, is valuable and we need to treat it as a precious commodity.

So the difference is not just who’s doing the testing. It’s the opportunity of working creatively, increasing value and doing interesting stuff, rather than lead a boring miserable life.

If you have some miracle-working story on how automation changed your life, please share in the comments.

Permanent link to this article: http://www.typemock.com/blog/2012/04/05/the-difference-between-automated-and-manual-testing/

Apr
02

Learn How to Start Unit Testing

Not sure how to start unit testing? Want fewer bugs?

Writing unit tests or performing Test Driven Development but finding it difficult?

We have the secrets of starting unit testing successfully and we’re spilling them this Wednesday.

Sign up here: http://www.typemock.com/introduction-to-unit-testing3

11_unit_testsJoin our webinar: Introduction to Unit Testing

When: Wednesday, April 4 at 10:00 AM Eastern Time (US & Canada), 3:00 PM British Standard Time, 7:30 PM India Standard Time.

In order to prevent bugs and release quality code to market, you also need developer testing, including unit testing. Discover why you should start unit testing, and how you can get started with automated tests quickly.

Learn: 

  • Benefits of unit testing
  • xUnit Frameworks
  • The difference between unit testing and test driven development (TDD).

Sign up here: http://www.typemock.com/introduction-to-unit-testing3

(By the way, if you are a first time attendee, you may win a Typemock Isolator license. Not to be missed!)

Permanent link to this article: http://www.typemock.com/blog/2012/04/02/learn-how-to-start-unit-testing/

Mar
28

Spending too much time debugging

We all hate debugging software and fixing bugs. But apparently some of us are spending several hours each day debugging and fixing software bugs.

Software bugs are something that we all have to deal with, right? This has been the convention wisdom for decades. As one person wrote “Debugging is part of coding.” But it’s just not true!

In a question that I posed on LinkedIn “How much time do you spend debugging,” I received several interesting answers. One person wrote: “I wouldn’t like to say how much time I’m debugging… it’s a lot and yes that bothers me! Probably upwards of 50% of my time is spent trying to figure out why something isn’t doing what’s expected.”
Hour Glass
Another said that “About 1 hour of my 8 hour work day is spent debugging.” Doesn’t sound like a lot? That’s 12% of your day. At least you’re not this other person who wrote that “I can spend … up to my entire working day resolving issues and getting things working again.” Of course, it’s also about how you define debugging and fixing errors in your code base. One person wrote, “I know this not not the best practice, but I belong to the old school “trial and error”, hence, I shall summarise by saying nearly 99% of my time is about debugging.”

Tools and techniques can help us spend less time pinpointing errors in our codebase. As one person wrote, “The better debugging techniques you have, the more time you save.”

My favorite answer to the question of how much time you spent debugging was very clear: “TOO MUCH TIME!”

Don’t you wish you could find and pinpoint the exact location of the bug immediately, as you’re coding? Now you can.

Permanent link to this article: http://www.typemock.com/blog/2012/03/28/spending-too-much-time-debugging/

Mar
27

Let the robot code for you

Learn how to start easy unit testing and let Typemock Isolator. Sign up for our webinar.

Really want to let the program do all the work for you? Download Typemock Isolator and it will find your bugs for you.

Really want to let the program do all the work for you? Download Typemock Isolator and it will find your bugs for you.

(Comic source: http://www.smbc-comics.com/)

 

Permanent link to this article: http://www.typemock.com/blog/2012/03/27/let-the-robot-code-for-you/

Mar
26

How To Name Your First Test

After your loving grandfather, of course.

Just kidding.

Naming tests correctly is a skill that can determine the effectiveness of your tests. Yes, really.

Effective tests do two things: warn you on the first sign of trouble, and help you fix the problem as soon as possible. The first one everyone knows intuitively. The second one? not so much.

But think about it: What’s the first thing you look at when the run turns red? The failing test name. If you called it “test1” it’s not that helpful. And by helpful I mean: I need to fix this quickly, and if possible, without debugging.

So obviously, naming is very important. What are the rules for proper naming?

Rule #1: Know what you’re testing

If you don’t, don’t bother with a name yet. What method is under test? What do you expect to happen? Under what circumstances? You must at least have this understood before writing a single line of test code.

Rule #2: Make it human readable

See, while your test runner can tell the difference between “pass” and “fail”, it doesn’t have a clue about the meaning of the  test name. It will be up to you, or another human on your team, that can see what’s going on. The name tells it all, mostly for us bipod beings.

Rule #3: Make it as long as you need

That’s what she said! About test names, of course. Put in as much information to make help the poor soul who happened to be on watch when the test failed. Instead of him trying to guess the hidden meaning, say it all. I use a convention of MethodUnderTest_SpecificScenario_ExpectedResult, which usually works, but on occasion may require more parts. You can use the BDD convention of Given_When_Then, or any other way that can help the reader understand what just didn’t work. Don’t skimp on characters!

Rule #4: Give it personality

Some uniqueness required. You may get the root of the problem by checking not just which tests failed, but also which still pass, comparing the different scenarios. If you named your tests with proper distinction, you can tell by looking at the different names of the tests related to our culprit. If you’re using Isolator V7, you get all that info, in one place, right there on the code!

Rule #5: Give it a test

If the test failed on your watch, you can make sense of it, I’m sure (hidden sarcasm included). But what if it’s not you? Grab someone by the ear and make them read the name and tell you they understand it. If you pair-program you’ll get that for free.

There you have it. 5 simple rules for test naming heaven.

My heaven at least. Now it’s your turn.

Are there other rules you follow? What convention do you use? Tell us in the comments!

Start unit testing. Download Typemock Isolator.

Permanent link to this article: http://www.typemock.com/blog/2012/03/26/how-to-name-your-first-test/

Mar
21

A tax on software bugs?

How expensive might software become if one proposal to tax software bugs happens.

Geeknomics author and Apple’s new head of global security David Rice, has recently floated an idea to tax software bugs. According to Computer World, instead of consumers bearing the burden with shoddy, insecure software, the burden should shift to the manufacturers.
Software bug
According to the magazine, “If security related vulnerabilities were somehow taxed, the cost burden would be shifted more from the consumer of software to the software manufacturer.”

So, how can software companies ensure quality releases?

But, what’s the incentive for preventing software bugs, when it may lead to higher up-front costs – even if the overall, long-term cost is less.

In addition to the software tax, some other ideas, for rewarding well-engineered software include:

  • A 5 star security rating, to help software buyers understand the implication of an application through third-party evaluation. “The idea is to give consumers the information they need to make better decisions. This would improve the efficiency of the market for software,” says Josh Corman, research director at the 451 Group’s enterprise security practice. “People today, generally, have no idea how to judge the quality of software as it relates to security. Such information would provide the clarity a market needs to function,” he says.
  • Liability and tort reform, to make it easier to sue software makers for the damages created by faulty software. The goal is to shift the costs of shoddy software from the consumer to the manufacturer
  • Software recalls: if the faults are dangerous enough, recalling shoddy software may be a way to help reduce software bugs. However, many recalls, such as car recalls, often already occur due to software faults.

Of course, we think the best way to prevent software bugs is through unit testing with Isolator V7. Isolator V7 is the only unit testing framework that identifies not only failed tests but actually pinpoints the location of the bugs. Have you tried it out yet? Download it now.

What do you think? How can software developers have incentives to minimize bugs?

Permanent link to this article: http://www.typemock.com/blog/2012/03/21/a-tax-on-software-bugs/

Mar
18

Webinar: Find More Bugs in Less Time (and check out V7!)

Learn how to develop code more efficiently by identifying more bugs during the early stages of development.

We will learn how to

• Get Immediate feedback of newly introduced bugs 
• Pinpoint identification of the bug’s location 
• See what to test next 
• How to write tests for your code, whether new code or legacy code

Wednesday, March 21 at 11:00 AM ET, 15:00 UK (for US and Europe) — Click here to sign up

Thursday, March 22 at 13:00 Moscow, 20:00 Sydney, Australia (for Europe and Asia) – Click here to sign up

Learn more: http://www.typemock.com/find-more-bugs-in-less-time

We are also raffling off licenses of Typemock Isolator V7 to select winners at both winners. Sign up and win.

Permanent link to this article: http://www.typemock.com/blog/2012/03/18/webinar-find-more-bugs-in-less-time-and-check-out-v7/

Mar
13

Isolator V7 Released!

Yes! It’s out! And you can download it right now from the site.

So what have we got for you this time?

  • New auto-runner, running the relevant tests automatically on every build. The auto-runner intelligently separates the quick unit tests from the long-running tests to get you the most immediate feedback.

V7 - Potential Bugs Zoom

  • The Failed-Test analyzer helps you find the bugs quickly. It knows what production code changes failed the tests, so you can get there in a click. Once there, you can see which tests pass and which fail and why, giving you all the information to solve the bug.  Experimenting on our team (we do that sometimes), they say that Isolator finds the bugs for them!

V7 - Debug Tests

  • Visual code coverage, you can see on your code what tests cover it. As we’ve learned from experimenting on our own developers, seeing missing shields, actually compells them to write tests for un-covered code. It’s amazing!

The very powerful mocking framework got even more powerful

  • Version compatibility from version 5.3.2 and on. This allows to run tests with different versions of Isolator on the same machine without hassle
  • New mocking capabilities:
    • Isolate.Invoke.StaticConstructor<> : To invoke that static constructor when you actually need it.
    • Isolate.Fake.Dependencies<> and Isolate.GetFakes: Create an isolated object, by faking the dependencies in the constructor implicitly. Not only a time-saver, since you don’t need to set up all the dependencies yourself, this is also making the test more robust, since it doesn’t really suffer from changes it doesn’t know about
    • Isolate.Swap.NextInstance<>.WithRecursiveFake: Create a fake future object in one line, instead of two.
    • More supported MSCorLib types: File, FileStream and Environment
  • Support linking with the latest JetBrains dotCover and dotTrace tools.
  • A Microsoft TFS activity for build server integration

And bug fixes galore, too!

But don’t take my word for it (if you know me, well, that goes without saying).

See for yourself, download it right now. And, to hear more, join me in the webinar we’re doing next week for the launch.

Permanent link to this article: http://www.typemock.com/blog/2012/03/13/isolator-v7-released/

Mar
12

Software Development Cycle: Does your organization look like this?

  1. Programmer produces code he believes is bug-free.

  2. Product is tested. 20 bugs are found.

  3. Programmer fixes 10 of the bugs and explains to the testing department that the other 10 aren’t really bugs.

  4. Testing department finds that five of the fixes didn’t work and discovers 15 new bugs.

  5. Repeat three times steps 3 and 4.

  6. Due to marketing pressure and an extremely premature product announcement based on overly-optimistic programming schedule, the product is released.

  7. Users find 137 new bugs.

  8. Original programmer, having cashed his royalty check, is nowhere to be found.

  9. Newly-assembled programming team fixes almost all of the 137 bugs, but introduce 456 new ones.

  10. Original programmer sends underpaid testing department a postcard from Fiji. Entire testing department quits.

  11. Company is bought in a hostile takeover by competitor using profits from their latest release, which had 783 bugs.

  12. New CEO is brought in by board of directors. He hires a programmer to redo program from scratch.

  13. Programmer produces code he believes is bug-free…

(Source)

If only the programmers had something that would find the bugs for them after the build. Oh wait, now they do. Download Isolator V7 and learn more about it in a webinar:

Wednesday March 21 at 8:00 AM Pacific time, 11:00 AM Eastern time – Register Here

or

Thursday March 22 at 10:00 AM UK, 2:30 PM India, 8:00 PM Australia (AEDT) – Register Here

Permanent link to this article: http://www.typemock.com/blog/2012/03/12/software-development-cycle-does-your-organization-look-like-this/

Older posts «

» Newer posts