Unit Testing Tools in WebForms Core 2: A Deep Dive
Explore unit testing tools in WebForms Core 2, featuring AssertEqual for deep DOM comparisons and seamless integration in your development workflow.

Why Is Unit Testing Crucial in WebForms Core 2?
Unit testing stands as a fundamental aspect of trustworthy web development, particularly when using frameworks like WebForms Core 2. For developers, it's essential to ensure applications behave as expected during modifications. WebForms Core 2 offers a comprehensive unit testing toolkit, simplifying your testing efforts.
This technology combines a client-side library, WebFormsJS, with a server-side class, WebForms, automating their interaction to reduce errors. Elanat has further improved this by introducing a streamlined unit testing tool in WebForms Core 2's second version, enhancing testing efficiency and accessibility.
Meet AssertEqual: Your Unit Testing Ally
At the core of the unit testing toolkit lies the AssertEqual function. This tool lets you conduct thorough comparisons of DOM elements to verify if your HTML output aligns with your expectations. Unlike other testing frameworks, WebForms Core 2 incorporates this utility directly, eliminating the need for extra dependencies.
How Does AssertEqual Work?
AssertEqual excels in comparing two DOM elements—one actual and one expected. It evaluates both structural and visual similarities, accommodating HTML strings and DOM nodes. This versatility proves beneficial across various testing scenarios.
AssertEqual's Key Features
- Deep DOM Comparison: Validates the structure, including child nodes and text.
- Form Support: Efficiently manages form elements' values and states.
- Attribute & Style Checks: Ensures attributes, classes, and inline styles match precisely.
- Clear Reporting: Provides easy-to-understand messages for any discrepancies in the console.
- Simple API: Offers a true or false outcome for easy workflow integration.
The AssertEqualByOutputPlace Function
For more focused testing, the AssertEqualByOutputPlace function is recommended. It assesses an existing tag rather than the entire tag string, offering a more concentrated comparison method.
Understanding AssertEqualByOutputPlace
AssertEqualByOutputPlace(InputPlace, OutputPlace)
This function conducts various checks:
- Tag Name Matching: Confirms the use of identical HTML tags.
- Attribute Comparison: Identifies discrepancies in attributes.
- Class List Verification: Ensures class names match, irrespective of order.
- Inline Style Matching: Checks for exact inline style matches.
- Form Value Validation: Compares form elements' values and states.
- Child Node Recursion: Deeply compares child nodes for comprehensive analysis.
All differences are clearly logged, providing transparent feedback while maintaining code execution.
Practical Examples: AssertEqual in Action
Here's how AssertEqual can be utilized in WebForms Core 2 for component validation.
Example 1: HTML String Testing
form.AssertEqual("myButton", "<button id='myButton' class='primary'>Click Me</button>");
Example 2: Element Testing
form.AssertEqualByOutputPlace("myButton1", "myButton2");
These commands effortlessly validate dynamic rendering, form creation, and component output.
A Real-World Testing Scenario
Consider testing the following HTML structures:
<!-- Example HTML structures for testing -->
Executing the server code below tests the elements:
form.AssertEqualByOutputPlace("actualElement", "differentElement");
Console Feedback
The console will display detailed feedback like:
🔍 Start unit testing assert equal
ℹ️ [ASSERT FAIL] Class list mismatch: expected [form-wrapper] but got [form-container]
ℹ️ [ASSERT FAIL] Style mismatch: expected "background: #f5f5f5; padding: 15px;" but got "background: white; padding: 20px;"
... (additional mismatches)
⚠️ [ASSERT FAIL] Differences found
🔍 End unit testing assert equal
This information is crucial for debugging and improving your code.
Conclusion: Boosting Development with WebForms Core 2
WebForms Core 2 revolutionizes developers' approach to unit testing. With AssertEqual and AssertEqualByOutputPlace, writing impactful tests for UI logic becomes efficient. These tools offer clarity, accuracy, and flexibility in just a few lines of code. Integrating these utilities into your development process will elevate your application's reliability and performance, enabling you to deliver superior software.
Related Articles
The Story Behind Peaceful Night: A Calm Space for Tired Minds
Explore the journey of Peaceful Night, an app crafted for those seeking simplicity and tranquility in their quest for restful sleep.
Nov 15, 2025

The Most Hated CSS Feature: Understanding tan()
Explore the reasons behind the disdain for tan() in CSS and learn how to use it effectively, or find simpler alternatives for your projects.
Nov 13, 2025

GoREST is Dead: A New Era with GoREST 0.2.0
GoREST has officially transitioned from version 0.1 to 0.2.0, focusing on flexibility and performance. Join the journey as we redefine REST API development.
Nov 12, 2025
