Northwind2 - Unit Tests

Josef P.

Well-known member
Local time
Today, 09:46
Joined
Feb 2, 2023
Messages
994
At this point I thank the Northwind2 creators, I can use the file well for testing my unit test application, since with it the own "operation blindness" is minimized somewhat.

Now I will show how such a test can run. Maybe I'll get some of you to think about securing your own code with unit tests. ;)
Note: Unit tests can also be done with Rubberduck.

For example, an AccUnit test looks like this:
Code:
'AccUnit:Row("a{0}|b{1}|c{2}", New Integer() {0, 1, 2}, "a0|b1|c2")
'AccUnit:Row("a{0}|b{1}|c{2}", New Integer() {1, 2, 3}, "a1|b2|c3")
'AccUnit:Row("a{0}|b{1}", New Integer() {2, 3}, "a2|b3")
Public Sub StringFormat_TestWithIntegerArray(ByVal s As String, ByRef params() As Long, ByVal Expected As String)
   ' Arrange
   Dim Actual As String
   ' Act
   Actual = StringFormat(s, params)
   ' Assert
   Assert.That Actual, Iz.EqualTo(Expected)
End Sub

'AccUnit:Row("a{0}|b{1}", New Object() {2, "x"}, "a2|bx")
'AccUnit:Row("a{0}|b{1}|c{2}", New Object() {2, "x", #1/2/2023#}, "a2|bx|c02.01.2023").Name = "with date / localization!!!"
Public Sub StringFormat_TestWithVariantArray(ByVal s As String, ByRef params() As Variant, ByVal Expected As String)
   ' Arrange
   Dim Actual As String
   ' Act
   Actual = StringFormat(s, params)
   ' Assert
   Assert.That Actual, Iz.EqualTo(Expected)
End Sub

A test for StringFormatSQL that requires a correction of the function:
Code:
'AccUnit:Row("X = {0}", 1, "X = 1")
'AccUnit:Row("X = {0}", 1.2, "X = 1.2").Name = "will fail if DE (1.2 vs 1,2)"
Public Sub StringFormatSQL_NumericValues(ByVal s As String, ByVal p As Variant, ByVal Expected As String)
   ' Arrange
   Dim Actual As String
   ' Act
   Actual = StringFormatSQL(s, p)
   ' Assert
   Assert.That Actual, Iz.EqualTo(Expected)
End Sub
... Solution: Use Str(...) to convert numbers to SQL text.

How such a test works is shown in this video: https://accunit.access-codelib.net/videos/examples/NW2-UnitTests.mp4
 
Last edited:

Users who are viewing this thread

Back
Top Bottom