Monday, November 14, 2011

The Context Diagram


The Context Diagram shows the system under consideration as a single high-level process and then shows the relationship that the system has with other external entities (systems, organizational groups, external data stores, etc.). 

Another name for a Context Diagram is a Context-Level Data-Flow Diagram or a Level-0 Data Flow Diagram.  Since a Context Diagram is a specialized version of Data-Flow Diagram, understanding a bit about Data-Flow Diagrams can be helpful.

A Data-Flow Diagram (DFD) is a graphical visualization of the movement of data through an information system. DFDs are one of the three essential components of the structured-systems analysis and design method (SSADM). A DFD is process centric and depicts 4 main components.

  • Processes (circle)
  • External Entities (rectangle)
  • Data Stores (two horizontal, parallel lines or sometimes and ellipse)
  • Data Flows (curved or straight line with arrowhead indicating flow direction)
Each DFD may show a number of processes with data flowing into and out of each process.  If there is a need to show more detail within a particular process, the process is decomposed into a number of smaller processes in a lower level DFD. In this way, the Content Diagram or Context-Level DFD is labeled a “Level-0 DFD” while the next level of decomposition is labeled a “Level-1 DFD”, the next is labeled a “Level-2 DFD”, and so on.

Context Diagrams and Data-Flow Diagrams were created for systems analysis and design.  But like many analysis tools they have been leveraged for other purposes.  For example, they can also be leveraged to capture and communicate the interactions and flow of data between business processes. So, they don’t have to be restricted to systems analysis.

A sample Context Diagram is shown here.

A sample Context Diagram

A Context Diagram (and a DFD for that matter) provides no information about the timing, sequencing, or synchronization of processes such as which processes occur in sequence or in parallel.  Therefore it should not be confused with a flowchart or process flow which can show these things.

Some of the benefits of a Context Diagram are:

  • Shows the scope and boundaries of a system at a glance including the other systems that interface with it
  • No technical knowledge is assumed or required to understand the diagram
  • Easy to draw and amend due to its limited notation
  • Easy to expand by adding different levels of DFDs
  • Can benefit a wide audience including stakeholders, business analyst, data analysts, developers

Software Models

http://www.excelsoftware.com/models.html

Class Models
Class Model
Class diagrams are fundamental to object-oriented analysis and design. These diagrams show the static structure of object classes and important relationships between them. The Unified Modeling Language (UML) is the industry standard notation for class diagrams.
Data Models
Data Model
An entity-relation diagram, called an ERD illustrates the data structure of an information system. A database can be designed using logical and physical data models that highlight primary and foreign keys. Martin's Information Engineering notation is typically used for data models.
Process Models
Process Model
Process models, also called data flow diagrams (DFDs) start with a top level context diagram for a system. The system is represented as a named process with data flows in and out to the external world. The most popular notations are Yourdon/DeMarco for technical software and Gane & Sarson for business systems.
The system process explodes to a child diagram where its split into smaller processes connected by flows and stores to illustrate data flow and transformation.
Flows in and out of the system process must balance with flows in and out of its child diagram. This diagram leveling process continues until primitive processes yield a short textual description.
State Models
State Model
The essential behavior of systems can often be expressed with a state model. State diagrams show events, states and actions in various notations including Mealy, Moore and UML/Harel.
States and events can be shown with tables including the Hatley/Pirbhai Process Activation Table, Decision Table, State Transition Matrix, State Transition Table, Shlaer/Mellor State Transition Table and Event List.
Causal Loop diagrams show causal affects between system variables. Apply this model to any dynamic system to enable parameterization and time simulations.
A Flow Chart uses different styles of named boxes connected by arrowed lines to show how an algorithm or process works.
Structure Models
Structure Model
Structure Chart diagrams illustrate the organization of procedural programs. Each thread of execution begins with a root module at the top of an inverted tree of called modules.
When programs become large, functional branches of a tree get pushed down to a child diagram creating a linked stack of diagrams that highlight the program's structure.
Object Models
Object Model
An object model shows object instances, their operations and messages between objects to document the mechanisms within an object-oriented design. Each diagram illustrates part of the design with a collection of communicating objects.
Popular notations include UML Sequence diagrams, UML Collaboration, Booch, Fusion and Shlaer/Mellor.
Task Models
Task Model
The Task window is used to create diagrams showing system architecture and task interactions in a multi-tasking environment. The UML Deployment diagram is a type of task diagram that shows the configuration of run-time processing elements.
Specification
Specification
The Specification window is used to create textual specifications of design elements and diagram objects. Click to the specification editor for a selected diagram object.
Code
Code
The Code or Browse window is used to view or edit code. Click to associated source code for a selected diagram object. Use the integrated Browse window to navigate through classes, attributes and operations in an object-oriented development project.
Test
Test
The Test window is used to view or edit test designs and procedures. Click to the test editor for a selected diagram object or requirement entry. Test files can be edited with the built-in test editor or with a configured custom editor.
HTML
HTML
Popular web browsers like Netscape or Internet Explorer can be used to view HTML files linked to selected diagram objects. Scriptable HTML reports make your diagrams, specifications, requirements, dictionary and code or test files easily accessible to any web browser.
Dictionary
Dictionary
The Dictionary window is used to create textual specifications of design elements and diagram objects. Designers can work with dictionary information directly from the Dictionary window or indirectly by editing diagrams.
Requirements
Requirements
The Requirement window is used to define the functional requirements of a system. Data is entered through a dialog controlled by a user-defined template of fields. The textual description of each use case is also defined here. Requirement entries can be linked to models, specifications or code files with two-way traceability.
CRC Models
CRC Model
CRC cards are an agile technique for modeling each class in an object-oriented system. Each card identifies the class name, its attributes, responsibilities (operations) and collaborations with other classes. Design scenarios can be identified and simulated.
Charts
Charts
Dynamic tables, charts and graphs present project statistics or simulation results.
Data Files
Data Files
Data files are used to drive system models during simulation or store generated results. Data items of type Variable, Array or List can be imported or exported to other applications like spreadsheets and databases.
Team Data Dictionary
Team Data Dictionary
The Team Dictionary allows multi-user access to dictionary information. Use the Team window for viewing active users and change records.
Team Requirements
Team Requirements
The Team Requirements document allows multi-user access to requirement information.


Modeling Tools
MacA&D Box WinA&D Box MacA&D and WinA&D are integrated modeling tools designed for team development, distributed projects, multiple methods and large systems.
Get a complete solution for system modeling and simulation, requirements management, software design, code generation and flexible reports.
MacA&D and WinA&D support UML 2.2.

QuickUML Box QuickUML implements a core set of models from the Unified Modeling Language notation. This highly integrated UML design tool is easy to learn and well suited for Agile methods.
QuickCRC Box QuickCRC implements responsibility-driven design with CRC cards. Create CRC cards and design scenarios for an object-oriented software design project.



Process Model (Data Flow Diagrams)

The process model is a core diagram in structured analysis and design. Also called a data flow diagram (DFD), it shows the flow of information through a system. Each process transforms inputs into outputs.
The model generally starts with a context diagram showing the system as a single process connected to external entities outside of the system boundary. This process explodes to a lower level DFD that divides the system into smaller parts and balances the flow of information between parent and child diagrams. Many diagram levels may be needed to express a complex system.
Primitive processes, those that don't explode to a child diagram, are usually described in a connected textual specification. This text is sometimes referred to as a mini-spec. It textually describes how the outputs are generated from the inputs.
When drawing data flow diagrams, the designer adds an entry for each data flow or store into a data dictionary. The data dictionary integrates the stack of diagrams into a cohesive model by defining all the names and data composition.
The balancing process ensures that data is conserved between diagram levels. If flow A enters a parent process, its child diagram should have flow A coming into that diagram. Likewise flow B leaving the child diagram should balance with flow B leaving the parent process. Data decomposition can occur within the data dictionary so flow A into the parent process will balance if flows X and Y enter the child diagram and A = X + Y in the data dictionary.

Yourdon/DeMarco DFD

A Yourdon/DeMarco style DFD is shown below. It includes both data flow (solid lines) and control flow (dotted lines) as specified in the Hatley/Pirbhai method. This DFD style is typically used in real-time system analysis and design.
Yourdon/DeMarco Data Flow Diagram (DFD)

Gane & Sarson DFD

The Gane & Sarson style DFD shown below is typically used for information systems. Here we show the flow of information in a small software company.
Gane and Sarson Data Flow Diagram (DFD)

Component Diagram

Overview

Components are wired together by using an assembly connector to connect the required interface of one component with the provided interface of another component. This illustrates the service consumer - service provider relationship between the two components.
An assembly connector is a "connector between two components that defines that one component provides the services that another component requires. An assembly connector is a connector that is defined from a required interface or port to a provided interface or port."[1]
When using a component diagram to show the internal structure of a component, the provided and required interfaces of the encompassing component can delegate to the corresponding interfaces of the contained components.
A delegation connector is a "connector that links the external contract of a component (as specified by its ports) to the internal realization of that behavior by the component’s parts."[1]
The example above illustrates what a typical Insurance policy administration system might look like. Each of the components depicted in the above diagram may have other component diagrams illustrating their internal structure.


The basics
Drawing a component in UML 2 is now very similar to drawing a class on a class diagram. In fact, in UML 2 a component is merely a specialized version of the class concept. Which means that the notation rules that apply to the class classifier also apply to the component classifier. (If you read and understood my previous article [http://www-106.ibm.com/developerworks/rational/library/content/RationalEdge/sep04/bell/index.html] regarding structure diagrams in general, and class diagrams in particular, you are well under way to understanding component diagrams.)
In UML 2, a component is drawn as a rectangle with optional compartments stacked vertically. A high-level, abstracted view of a component in UML 2 can be modeled as just a rectangle with the component's name and the component stereotype text and/or icon. The component stereotype's text is «component»" and the component stereotype icon is a rectangle with two smaller rectangles protruding on its left side (the UML 1.4 notation element for a component). Figure 2 shows three different ways a component can be drawn using the UML 2 specification.

Figure 2: The different ways to draw a component's name compartment
The different ways to draw a component's name compartment
When drawing a component on a diagram, it is important that you always include the component stereotype text (the word "component" inside double angle brackets, as shown in Figure 2) and/or icon. The reason? In UML, a rectangle without any stereotype classifier is interpreted as a class element. The component stereotype and/or icon distinguishes this rectangle as a component element.
Modeling a component's interfaces Provided/Required
The Order components drawn in Figure 2 all represent valid notation elements; however, a typical component diagram includes more information. A component element can have additional compartments stacked below the name compartment. As mentioned earlier, a component is an autonomous unit that provides one or more public interfaces. The interfaces provided represent the formal contract of services the component provides to its consumers/clients. Figure 3 shows the Order component having a second compartment that denotes what interfaces the Order component provides and requires. [Note: Even though components are autonomous units they still may depend on the services provided by other components. Because of this, documenting a component's required interfaces is useful.]

Figure 3: The additional compartment here shows the interfaces that the Order component provides and requires
Additional compartment showing the interfaces that the Order component provides and requires
In the example Order component shown in Figure 3, the component provides the interfaces of OrderEntry and AccountPayable. Additionally, the component also requires another component that provides the Person interface. [Note: Figure 3 does not show the Order component in its complete context. In a real-world model the OrderEntry, AccountPayable, and Person interfaces would be present in the system's model.]
Another approach to modeling a component's interfaces
UML 2 has also introduced another way to show a component's provided and required interfaces. This second way builds off the single rectangle, with the component's name in it, and places what the UML 2 specification calls interface symbols" connected to the outside of the rectangle. This second approach is illustrated in Figure 4.

Figure 4: An alternative approach (compare with Figure 3) to showing a component's provided/required interfaces using interface symbols
Alternative approach to showing a component's provided/required interfaces using interface symbols
In this second approach the interface symbols with a complete circle at their end represent an interface that the component provides — this lollipop" symbol is shorthand for a realization relationship of an interface classifier. Interface symbols with only a half circle at their end (a.k.a. sockets) represent an interface that the component requires (in both cases, the interface's name is placed near the interface symbol itself). Even though Figure 4 looks much different from Figure 3, both figures provide the same information — i.e., the Order component provides two interfaces: OrderEntry and AccountPayable, and the Order component requires the Person interface.
Modeling a component's relationships
When showing a component's relationship with other components, the lollipop and socket notation must also include a dependency arrow (as used in the class diagram). On a component diagram with lollipops and sockets, note that the dependency arrow comes out of the consuming (requiring) socket and its arrow head connects with the provider's lollipop, as shown in Figure 5.

Figure 5: A component diagram that shows how the Order System component depends on other components
A component diagram that shows how the Order System component depends on other components
Figure 5 shows that the Order System component depends both on the Customer Repository and Inventory System components. Notice in Figure 5 the duplicated names of the interfaces CustomerLookup" and ProductAccessor." While this may seem unnecessarily repetitive in this example, the notation actually allows for different interfaces (and differing names) on each component depending on the implementation differences (e.g., one component provides an interface that is a subclass of a smaller required interface).
Subsystems
In UML 2 the subsystem classifier is a specialized version of a component classifier. Because of this, the subsystem notation element inherits all the same rules as the component notation element. The only difference is that a subsystem notation element has the keyword of subsystem" instead of component," as shown in Figure 6.

Figure 6: An example of a subsystem element
An example of a subsystem element
The UML 2 specification is quite vague on how a subsystem is different from a component. The specification does not treat a component or a subsystem any differently from a modeling perspective. Compared with UML 1.x, this UML 2 modeling ambiguity is new. But there's a reason. In UML 1.x, a subsystem was considered a package, and this package notation was confusing to many UML practitioners; hence UML 2 aligned subsystems as a specialized component, since this is how most UML 1.x users understood it. This change did introduce fuzziness into the picture, but this fuzziness is more of a reflection of reality versus a mistake in the UML 2 specification.
So right now you are probably scratching your head wondering when to use a component element versus a subsystem element. Quite frankly, I do not have a direct answer for you. I can tell you that the UML 2 specification says that the decision on when to use a component versus a subsystem is up to the methodology of the modeler. I personally like this answer because it helps ensure that UML stays methodology independent, which helps keep it universally usable in software development.
Beyond the basics
The component diagram is one of the easier-to-understand diagrams, so there is not much to cover beyond the basics. However, there is one area you may consider somewhat advanced.
Showing a component's internal structure
There will be times when it makes sense to display a component's internal structure. In my previous article on the class diagram, I showed how to model a class's internal structure; here I will focus on how to model a component's internal structure when it is composed of other components.
To show a component's inner structure, you merely draw the component larger than normal and place the inner parts inside the name compartment of the encompassing component. Figure 7 show's the Store's component inner structure.

Figure 7: This component's inner structure is composed of other components
Shows component's inner structure is composed of other components
Using the example shown in Figure 7, the Store component provides the interface of OrderEntry and requires the interface of Account. The Store component is made up of three components: Order, Customer, and Product components. Notice how the Store's OrderEntry and Account interface symbols have a square on the edge of the component. This square is called a port. In a simplistic sense, ports provide a way to model how a component's provided/required interfaces relate to its internal parts. [Note: In actuality, ports are applicable to any type of classifier (i.e., to a class or some other classifier your model might have). To keep this article simple, I refer to ports in their use on component classifiers.
By using a port, our diagram is able to de-couple the internals of the Store component from external entities. In Figure 7, the OrderEntry port delegates to the Order component's OrderEntry interface for processing. Also, the internal Customer component's required Account interface is delegated to the Store component's required Account interface port. By connecting to the Account port, the internals of the Store component (e.g. the Customer component) can have a local representative of some unknown external entity which implements the port's interface. The required Account interface will be implemented by a component outside of the Store component. [Note: Typically, when you draw a dependency relationship between a port and an interface, the dependent (requiring) interface will handle all the processing logic at execution time. However, this is not a hard and fast rule — it is completely acceptable for the encompassing component (e.g., the Store component in our example) to have its own processing logic instead of merely delegating the processing to the dependant interface.]
You will also notice in Figure 7 that the interconnections between the inner components are different from those shown in Figure 5. This is because these depictions of internal structures are really collaboration diagrams nested inside the classifier (a component, in our case), since collaboration diagrams show instances or roles of classifiers. The relationship modeled between the internal components is drawn with what UML calls an assembly connector." An assembly connector ties one component's provided interface with another component's required interface. Assembly connectors are drawn as lollipop and socket symbols next to each other. Drawing these assembly connectors in this manner makes the lollipop and socket symbols very easy to read.
Conclusion
The component diagram is a very important diagram that architects will often create early in a project. However, the component diagram's usefulness spans the life of the system. Component diagrams are invaluable because they model and document a system's architecture. Because component diagrams document a system's architecture, the developers and the eventual system administrators of the system find this work product-critical in helping them understand the system.

Friday, November 11, 2011

Unified Modeling Language

http://en.wikipedia.org/wiki/Unified_Modeling_Language

Unified Modeling Language (UML) is a standardized general-purpose modeling language in the field of object-oriented software engineering. The standard is managed, and was created, by the Object Management Group. It was first added to the list of OMG adopted technologies in 1997, and has since become the industry standard for modeling software-intensive systems.[1]
UML includes a set of graphic notation techniques to create visual models of object-oriented software-intensive systems.

Overview

The Unified Modeling Language (UML) is used to specify, visualize, modify, construct and document the artifacts of an object-oriented software-intensive system under development.[2] UML offers a standard way to visualize a system's architectural blueprints, including elements such as:
UML combines techniques from data modeling (entity relationship diagrams), business modeling (work flows), object modeling, and component modeling. It can be used with all processes, throughout the software development life cycle, and across different implementation technologies.[4] UML has synthesized the notations of the Booch method, the Object-modeling technique (OMT) and Object-oriented software engineering (OOSE) by fusing them into a single, common and widely usable modeling language.[citation needed] UML aims to be a standard modeling language which can model concurrent and distributed systems. UML is a de facto industry standard,[citation needed] and is evolving under the auspices of the Object Management Group (OMG).
UML models may be automatically transformed to other representations (e.g. Java) by means of QVT-like transformation languages. UML is extensible, with two mechanisms for customization: profiles and stereotypes.

Software development methods

UML is not a development method by itself;[11] however, it was designed to be compatible with the leading object-oriented software development methods of its time (for example OMT, Booch method, Objectory). Since UML has evolved, some of these methods have been recast to take advantage of the new notations (for example OMT), and new methods have been created based on UML, such as IBM Rational Unified Process (RUP). Others include Abstraction Method and Dynamic Systems Development Method.

[edit] Modeling

It is important to distinguish between the UML model and the set of diagrams of a system. A diagram is a partial graphic representation of a system's model. The model also contains documentation that drives the model elements and diagrams (such as written use cases).
UML diagrams represent two different views of a system model:[12]
UML models can be exchanged among UML tools by using the XMI interchange format.

[edit] Diagrams overview

UML 2.2 has 14 types of diagrams divided into two categories.[13] Seven diagram types represent structural information, and the other seven represent general types of behavior, including four that represent different aspects of interactions. These diagrams can be categorized hierarchically as shown in the following class diagram:
Hierarchy of UML 2.2 Diagrams, shown as a class diagram.
UML does not restrict UML element types to a certain diagram type. In general, every UML element may appear on almost all types of diagrams; this flexibility has been partially restricted in UML 2.0. UML profiles may define additional diagram types or extend existing diagrams with additional notations.
In keeping with the tradition of engineering drawings,[citation needed] a comment or note explaining usage, constraint, or intent is allowed in a UML diagram.

Structure diagrams

Structure diagrams emphasize the things that must be present in the system being modeled. Since structure diagrams represent the structure, they are used extensively in documenting the software architecture of software systems.
  • Class diagram: describes the structure of a system by showing the system's classes, their attributes, and the relationships among the classes.
  • Component diagram: describes how a software system is split up into components and shows the dependencies among these components.
  • Composite structure diagram: describes the internal structure of a class and the collaborations that this structure makes possible.
  • Deployment diagram: describes the hardware used in system implementations and the execution environments and artifacts deployed on the hardware.
  • Object diagram: shows a complete or partial view of the structure of an example modeled system at a specific time.
  • Package diagram: describes how a system is split up into logical groupings by showing the dependencies among these groupings.
  • Profile diagram: operates at the metamodel level to show stereotypes as classes with the <<stereotype>> stereotype, and profiles as packages with the <<profile>> stereotype. The extension relation (solid line with closed, filled arrowhead) indicates what metamodel element a given stereotype is extending.


[edit] Behaviour diagrams

Behaviour diagrams emphasize what must happen in the system being modelled. Since behaviour diagrams illustrate the behavior of a system, they are used extensively to describe the functionality of software systems.
  • Activity diagram: describes the business and operational step-by-step workflows of components in a system. An activity diagram shows the overall flow of control.
  • UML state machine diagram: describes the states and state transitions of the system.
  • Use case diagram: describes the functionality provided by a system in terms of actors, their goals represented as use cases, and any dependencies among those use cases.


[edit] Interaction diagrams

Interaction diagrams, a subset of behaviour diagrams, emphasize the flow of control and data among the things in the system being modeled:
  • Communication diagram: shows the interactions between objects or parts in terms of sequenced messages. They represent a combination of information taken from Class, Sequence, and Use Case Diagrams describing both the static structure and dynamic behavior of a system.
  • Interaction overview diagram: provides an overview in which the nodes represent communication diagrams.
  • Sequence diagram: shows how objects communicate with each other in terms of a sequence of messages. Also indicates the lifespans of objects relative to those messages.
  • Timing diagrams: a specific type of interaction diagram where the focus is on timing constraints.

The Protocol State Machine is a sub-variant of the State Machine. It may be used to model network communication protocols.

[edit] Meta modeling


Illustration of the Meta-Object Facility.
The Object Management Group (OMG) has developed a metamodeling architecture to define the Unified Modeling Language (UML), called the Meta-Object Facility (MOF). The Meta-Object Facility is a standard for model-driven engineering, designed as a four-layered architecture, as shown in the image at right. It provides a meta-meta model at the top layer, called the M3 layer. This M3-model is the language used by Meta-Object Facility to build metamodels, called M2-models. The most prominent example of a Layer 2 Meta-Object Facility model is the UML metamodel, the model that describes the UML itself. These M2-models describe elements of the M1-layer, and thus M1-models. These would be, for example, models written in UML. The last layer is the M0-layer or data layer. It is used to describe runtime instance of the system.
Beyond the M3-model, the Meta-Object Facility describes the means to create and manipulate models and metamodels by defining CORBA interfaces that describe those operations. Because of the similarities between the Meta-Object Facility M0-model and UML structure models, Meta-Object Facility metamodels are usually modeled as UML class diagrams. A supporting standard of the Meta-Object Facility is XMI, which defines an XML-based exchange format for models on the M3-, M2-, or M1-Layer.

Thursday, November 10, 2011

How to write effective Test cases, procedures and definitions

Writing effective test cases is a skill and that can be achieved by some experience and in-depth study of the application on which test cases are being written.
Here I will share some tips on how to write test cases, test case procedures and some basic test case definitions.
What is a test case?
“A test case has components that describes an input, action or event and an expected response, to determine if a feature of an application is working correctly.” Definition by Glossary
There are levels in which each test case will fall in order to avoid duplication efforts.
Level 1: In this level you will write the basic test cases from the available specification and user documentation.
Level 2: This is the practical stage in which writing test cases depend on actual functional and system flow of the application.
Level 3: This is the stage in which you will group some test cases and write a test procedure. Test procedure is nothing but a group of small test cases maximum of 10.
Level 4: Automation of the project. This will minimize human interaction with system and thus QA can focus on current updated functionalities to test rather than remaining busy with regression testing.
So you can observe a systematic growth from no testable item to a Automation suit.
Why we write test cases?
The basic objective of writing test cases is to validate the testing coverage of the application. If you are working in any CMMi company then you will strictly follow test cases standards. So writing test cases brings some sort of standardization and minimizes the ad-hoc approach in testing.
How to write test cases?
Here is a simple test case format
Fields in test cases:
Test case id:
Unit to test:
What to be verified?
Assumptions:
Test data:
Variables and their values
Steps to be executed:
Expected result:
Actual result:
Pass/Fail:
Comments:

So here is a basic format of test case statement:
Verify
Using
[tool name, tag name, dialog, etc]
With [conditions]
To [what is returned, shown, demonstrated]
Verify: Used as the first word of the test case statement.
Using: To identify what is being tested. You can use ‘entering’ or ‘selecting’ here instead of using depending on the situation.
For any application basically you will cover all the types of test cases including functional, negative and boundary value test cases.
Keep in mind while writing test cases that all your test cases should be simple and easy to understand. Don’t write explanations like essays. Be to the point.
Try writing the simple test cases as mentioned in above test case format. Generally I use Excel sheets to write the basic test cases. Use any tool like ‘Test Director’ when you are going to automate those test cases.

Thursday, November 3, 2011

Debugging and Tracing Ajax Applications Overview

AJAX-enabled ASP.NET applications contain a mix of server code and client code. The browser can also request additional data asynchronously. This can make debugging AJAX-enabled Web applications challenging. This overview discusses some techniques and tools that can help you debug your code more easily.

Note:

With the exception of Visual Studio and Internet Explorer, the programs mentioned in this topic are third-party tools and are not supported by Microsoft. Please see the tool's Web site for licensing and support information.

This topic contains:
  • Scenarios
  • Background
  • Class Reference

Scenarios

You can use the following approaches to debug an AJAX-enabled ASP.NET application at different stages of development:
  • Enable debugging in the configuration file.
  • Use tracing on the server.
  • Use the methods of the Sys.Debug class to set breakpoints and handle trace output.
  • Enable debugging in your browser.
  • Attach the Visual Studio 2010 debugger to your Internet Explorer instance, or use external tools to debug in other browsers.
  • Use external tools to capture HTTP traffic.

Background

The ASP.NET AJAX architecture provides a model for release and debug modes. Release mode provides error checking and exception handling that is optimized for performance, with minimized script size. Debug mode provides more robust debugging features, such as type and argument checking. If you create debug versions of client script files or script resources, ASP.NET runs the debug versions when the application is in debug mode. This enables you to throw exceptions in debug scripts but still keep the size of release code to a minimum.

A debug helper class, Sys.Debug, provides methods for displaying objects in readable form at the end of a Web page. It also shows trace messages, enables you to use assertions, and lets you break into the debugger. An extended Error object API provides helpful exception details with support for release and debug modes.

The following sections provide detail about the techniques and tools that you can use for debugging and tracing.

Configuring the Application for Debugging

To enable debugging, add a compilation element to the site's root Web.config file, and then set its debug attribute to true. For more information, see compilation Element (ASP.NET Settings Schema).

The following example shows a section from a Web.config file that has the debug attribute set for debugging.
  1. <configuration>  
  2.   <system.web>  
  3.     <compilation debug="true">  
  4.       <!-- etc. -->  
  5.     </compilation>  
  6.   </system.web>  
  7. <configuration>  

When debugging is enabled, ASP.NET uses a debug version of the Microsoft AJAX Library and debug versions of your custom client script files, if available.

Setting the Application from Debug to Release Mode for Deployment

When you deploy a release version of an AJAX-enabled ASP.NET application, set the application to release mode. This makes sure that ASP.NET uses the performance-optimized release version of the AJAX libraries. If you have created debug and release versions of your custom script files and script resources, ASP.NET also uses the release versions. To set the application to release mode, do the following:
  • In the Web.config file, if the compilation element contains a debug attribute, make sure that the debug attribute is set to false.
  • Make sure that any Web page that contains a ScriptManager control has its ScriptMode property set to Release.


The debug attribute of the @ Page directive does not affect ASP.NET AJAX applications. The ScriptManager control uses only the settings in the Web.config file and in its IsDebuggingEnabled and ScriptMode properties to determine whether to render debug scripts.

Tracing on the Server

If you are using tracing on the server to debug Web pages that have partial-page rendering enabled, you should use the trace viewer (Trace.axd) to display trace output. You can append trace output to the end of the page, and it is displayed the first time the page is rendered. However, the trace display is not updated as a result of asynchronous postbacks, because only the contents of UpdatePanel controls that have to be refreshed will change. For more information about how to use the trace viewer, see ASP.NET Tracing Overview.

Note:

Partial-page rendering is enabled when the page contains a ScriptManager control with its EnablePartialRendering property set to true. The page must also contain one or more UpdatePanel controls.

Debug Helper Class

ASP.NET provides the Sys.Debug class for debugging client applications. By calling methods of the Sys.Debug class, you can display objects in readable form at the end of the page, show trace messages, use assertions, and break into the debugger.

If you are using Visual Studio and Internet Explorer, you can attach the Visual Studio debugger to the browser and view debugger trace messages in the Output window. If you are not using Visual Studio, you can view debugger trace messages in Internet Explorer by creating a textarea element on the page and setting its ID to TraceConsole. In Mozilla Firefox, you can view debugger trace messages by using tools that are available as extensions. The Apple Safari and Opera browsers display trace messages in their respective debugging consoles.

The following table lists the methods of the Sys.Debug class.
  • Sys.Debug.assert(condition, message, displayCaller)
    Checks for a condition, and if the condition is false, displays a message and prompts the user to break into the debugger.
  • Sys.Debug.clearTrace()
    Clears all trace messages from the TraceConsole textarea element.
  • Sys.Debug.traceDump(object, name)
    Dumps an object to the debugger console and to the TraceConsole textarea element, if available.
  • Sys.Debug.fail(message)
    Displays a message in the debugger's output window and breaks into the debugger.
  • Sys.Debug.trace(text)
    Appends a text line to the debugger console and to the TraceConsole textarea element, if available.

The following example shows how to call methods of the Sys.Debug class:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head id="Head1" runat="server">  
  4.     <title>Untitled Page</title>  
  5. <script language="javascript" type="text/javascript">  
  6.     function btnAssert_onclick() {  
  7.         var n;  
  8.         // Insert code intended to set n to a positive integer.  
  9.         if (false) n = 3;  
  10.         // Assert if n is not greater than 0.  
  11.         Sys.Debug.assert(n > 0, "n must be set to a positive integer.");  
  12.     }  
  13.     function btnFail_onclick() {  
  14.         var n;  
  15.         // Insert code intended to set n to a numeric value.  
  16.         if (false) n = 3;  
  17.         // Fail if n is not numeric.  
  18.         if (isNaN(n)) Sys.Debug.fail("The value of n must be a number.");  
  19.     }  
  20.     function btnTrace_onclick() {  
  21.         v = form1.text1.value;  
  22.         Sys.Debug.trace("Name set to " + "\"" + v + "\".");  
  23.         alert("Hello " + v + ".");  
  24.     }  
  25.     function btnDump_onclick() {  
  26.         Sys.Debug.traceDump(form1.text1, "Name textbox");  
  27.         alert("Hello " + form1.text1.value + ".");  
  28.     }  
  29.     function btnClear_onclick() {  
  30.         Sys.Debug.clearTrace()  
  31.         alert("Trace console cleared.");  
  32.     }  
  33. </script>  
  34. </head>  
  35. <body>  
  36. <form id="form1" runat="server">  
  37.     <h2>Sys.Debug Methods Test Page</h2>  
  38.     <asp:ScriptManager ID="ScriptManager1" runat="server" />  
  39.     <p><b>Use these buttons to demonstrate the assert() and fail()   
  40.     methods:</b><br />  
  41.     <input id="btnAssert" type="button" value="Assert"   
  42.         style="width: 100px"   
  43.         onclick="return btnAssert_onclick()" /> &nbsp  
  44.     <input id="btnFail" type="button" value="Fail"   
  45.         style="width: 100px" onclick="return btnFail_onclick()" />  
  46.     </p><hr />  
  47.     <b>Use the textbox and buttons below to demonstrate tracing.</b>  
  48.     <br />  
  49.     <p>Enter your name here:<br />  
  50.     <input id="text1" maxlength="50" type="text" />  
  51.     <br />  
  52.     <br />  
  53.     <input id="btnTrace" type="button" value="Trace"   
  54.         style="width: 100px" onclick="return btnTrace_onclick()" /><br />  
  55.     <input id="btnDump" type="button" value="TraceDump"   
  56.         style="width: 100px" onclick="return btnDump_onclick()" /><br />  
  57.     <input id="btnClear" type="button" value="ClearTrace"   
  58.         style="width: 100px" onclick="return btnClear_onclick()" /><br />  
  59.     <br /></p>  
  60.     View output in the TraceConsole textarea below.  
  61.     <br />  
  62.     <textarea id='TraceConsole' rows="10" cols="50"   
  63.         title="TraceConsole"></textarea>  
  64. </form>  
  65. </body>  
  66. </html>  

Configuring Internet Explorer for Debugging

By default, Internet Explorer ignores problems that it encounters in JavaScript. You can enable debugging by using the following procedure.

To enable debugging in Internet Explorer

  1. In the Tools menu, click Internet Options.
  2. In the Advanced tab, clear the Disable Script Debugging (Internet Explorer) check box and the Disable Script Debugging (Other) check box.
  3. Select the Display a notification about every script error check box.
  4. To turn off "friendly" error messages, clear the Show friendly HTTP error messages check box.
    If "friendly" error message are enabled and if an HTTP 500 error response from the server is less than 513 bytes long, Internet Explorer masks the content. In place of the error information, Internet Explorer displays a message that is meant for end users, not developers.

Attaching the Visual Studio Debugger to Internet Explorer

To debug client script, you must attach a debugger to Internet Explorer. In Visual Studio, if you start your application for debugging (by pressing F5 or using the Start Debugging command in the Debug menu), the debugger is attached automatically.

You can also attach the Visual Studio debugger to Internet Explorer when the application is already running. To do so, in the Debug menu, click Attach to Process.... In the Attach to Process dialog box, select the instance of Internet Explorer (iexplore.exe) that you want to attach the debugger to.

Note:

If Internet Explorer is configured for debugging, the Type column for the relevant instance of Internet Explorer displays Script, x86. If you see only x86 in the Type column, make sure that Internet Explorer is configured for debugging.

If Internet Explorer encounters a script error and is configured for script debugging, but it is not currently attached to a debugger, the browser prompts you to select a debugger. You can either continue without debugging or attach a debugger and step through the code.

Internet Explorer Known Debugging Issues and Workarounds

When you debug ASP.NET AJAX applications that use Internet Explorer, be aware of the following issues and workarounds:
  • After the Visual Studio debugger is attached to Internet Explorer, you can see a list of the scripts that are being debugged in the Script Explorer window. (To display this window, in the Debug menu, click Windows, and then click Script Explorer). The ASP.NET AJAX client library will appear as a resource starting with ScriptResource.axd?..., which the server generates dynamically from the ASP.NET AJAX assembly. A known issue in Visual Studio might prevent you from opening the file. If Visual Studio displays an error message to that effect, or if it ignores clicks on the file name, close all script files that are open. You can then open the page and select the script files that you want to debug.
  • You cannot set breakpoints in JavaScript code inside script elements in an ASP.NET page until after the debugger has stepped into JavaScript code on that page. To work around this issue, set the breakpoint on the function that the call comes from, and step into the code on the ASP.NET Web page. After the debugger has stopped on a line of JavaScript code in the page, you can set breakpoints as usual. Another way to have the debugger recognize scripts in an ASP.NET page is to create a method in the ASP.NET page file that calls the Sys.Debug.fail method. When you call this method, the debugger will stop on the call to Sys.Debug.fail and let you set breakpoints elsewhere. A third alternative is to put all your custom code in external JavaScript files.
  • Visual Studio enables you to set breakpoints on the first line of a regular JavaScript function, but not on the first line of anonymous methods, which ASP.NET uses in AJAX libraries. If an anonymous method contains only one line of code, or if you must set a breakpoint on the first line of an anonymous method, insert a dummy line of code. You can then set the breakpoint on the second line of the method.

IIS 7.0 Known Issues

When you run ASP.NET AJAX-enabled pages by using IIS 7 on Windows Vista, and when the managed pipeline mode is set to Integrated, the scripts processed by the ScriptResourceHandler class are not cached. However, the scripts are cached when the managed pipeline mode is set to Classic.

For more information about the managed pipeline mode of IIS 7, see Upgrading ASP.NET Applications to IIS 7.0: Differences between IIS 7.0 Integrated Mode and Classic Mode.

Capturing HTTP Traffic

When you develop Web applications, it is often useful to monitor the HTTP traffic between the server and the client. A tool that can perform this task is Fiddler, which you can get from the Fiddler PowerToy page on the MSDN Web site. Fiddler runs as a proxy that logs all HTTP traffic. It supports Internet Explorer and other browsers. By using Fiddler, you can examine each request and response, which includes headers, cookies, and message contents.

Debugging in Mozilla Firefox

Mozilla Firefox is not integrated with the Visual Studio debugger. As a result, you cannot use the Visual Studio debugger to step through client code that is running in Firefox. However, Firefox supports some debugging functionality, such as a JavaScript console. You can also install the following extensions available from Mozilla that can enhance your debugging capabilities:
  • FireBug enables you to step through client script and examine HTML DOM elements. It also provides a script console, a command line, and other tools.
  • The JavaScript Debugger (also known as "Venkman") provides a JavaScript debugging environment that includes a source-code browser and other features.
  • The Web Developer extension enables you to inspect the DOM and CSS styles.

Fiddler also works with Firefox. However, you must configure Firefox to route HTTP requests through the proxy that is running on port 8888 on the local computer. For more information, see the "Configuring Clients" page on the Fiddler Web site.

Class Reference

Sys.Debug Class
Provides methods that define breakpoints and handle trace output.