Tuesday 17 December 2013

Variable scope in ASPX page

When you declare a variable in a Web Forms .aspx file, you’re actually declaring a local variable inside an auto-generated rendering method. ASP.NET generates separate rendering methods for all tags marked runat="server". So for example if you have a variable declared in <head> with runat=server its scope is limited to the <head>.

Read more>>

Tuesday 3 December 2013

Dealing with Bugs in Test Driven Development(TDD)

Although defect rates can be lower when using TDD, you will still create bugs. These should be corrected with the same three-phase iterations, Red, Green and Refactor. First you create one or more tests that demonstrate the bug by validating the correct behaviour. These tests should fail. Next you fix the code to make the test pass, performing regression testing by executing all of the tests. Once the bug is fixed, you should perform any appropriate refactoring to keep the code clean and readable.

Related articles

What is TDD?

TDD Process

Dealing with bugs in TDD

Test Driven Development (TDD) Process

The TDD process uses very short iterations, each adding a tiny amount of functionality to your software. Each iteration has three phases, described by the TDD mantra, "Red, Green, Refactor". The three phases are:

  • Red. The colour red refers to the colour shown in many automated test runners when a test fails. The idea is that before you write any production code you should write a failing test for that functionality. This often means writing test code that exercises classes or methods that have yet to be created. It is very important that every new test fails. New tests that pass immediately suggest that either the code they test is already present or that the test itself is defective. New tests should be small, aiming to test only a single aspect of the software being developed.
  • Green. The second phase of each iteration is writing code to make the new test pass. The smallest amount of code possible to make the test pass, without causing any existing tests to fail, is added to the project. This may mean creating dummy return values. For example, when creating a method that adds two values, the first test may check that adding two and three returns five. To make this test pass the method could return the fixed value of five, rather than performing an addition. Later tests will ensure that the method works correctly in all situations.
  • Refactor. A very important, though often overlooked, phase is refactoring. After creating a new test and making it pass you should consider the design of the code. Sometimes no refactoring is required. Other times you might change method or property names, or extract methods for a cleaner design. In some cases you may perform major refactoring of the code for an improved design. This is made easier because the existing tests can be run to ensure no bugs are introduced during the changes.

On completion of an iteration you simply start the process again. Usually an iteration is over in minutes, so most of the time you have working, if incomplete, code.

Related articles

What is TDD?

TDD Process

Dealing with bugs in TDD

What is Test Driven Development (TDD)?

  • Test-driven development (TDD) is an iterative development process.
  • The process relies on writing unit tests before creating the code that they validate.
  • The TDD process uses very short iterations, each adding a tiny amount of functionality to your software.
  • Each iteration has three phases, described by the TDD mantra, "Red, Green, Refactor".
  • TDD assists in creating high quality, well designed, loosely coupled and maintainable code that can be refactored with confidence.

Some development practices and methodologies lead to code that grows in complexity over time, with a corresponding decrease in maintainability. You may find that some projects are hard to modify, as adding new features might break existing functionality or cause subtle bugs that are difficult to rectify without introducing further defects. When you encounter such projects it may be difficult to incorporate small changes. Large refactoring operations can be near impossible.

If a project includes a high level of unit test coverage, meaning that most or all of the source code has tests to validate their functionality, it is likely to be easier to maintain. The key reason for this is that, in order to perform high quality testing, the code must be loosely coupled and is more likely to have a better design. In addition, you can confidently make changes to code that has a full set of tests, knowing that those tests will fail if you introduce errors.

Test-driven development (TDD) is an iterative development process that aims to achieve high standards of design, excellent testability of source code and high test coverage for your projects. As the name suggests, the process is driven by the creation of automated unit tests.

Related articles

What is TDD?

TDD Process

Dealing with bugs in TDD