Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 28 / 68

Checking correctness with Debug.Assert (a first step towards testing)

This lesson covers writing a simple test with VB.NET's Debug.Assert, with the aim of taking the first step towards checking your program is correct.

Debug.Assert() confirms that a result is what you expected, reporting a problem during development when the condition is false. It is a good way in to the idea of writing tests.

The sample code checks with an If statement whether Add(2, 3) gives 5, printing a pass or a fail accordingly. It gives you a feel for confirming a result in code rather than by eye.

A common early stumble is checking behaviour by hand every time and missing something. Leaving the condition in code means the same check can be repeated easily whenever the code changes.

In professional work, a proper test framework is used rather than Debug.Assert, but the underlying idea — compare the expected result with the actual one — is exactly what you have learned here.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)