Day 005 - From strings to unit tests

Strings! In all but the most numerically intensive apps, strings are the most common data type. 

In WinDev you can assign a value directly to a control. That surprises me a little because a control is a complex type. But this works:

EDT_FirstName = "Dave"

The concatenation operator is + (plus sign).

You can do string slicing using double square brackets. But it wasn't clear to me whether it's possible to write a string using string slicing, so I decided to run some tests.

Down the testing rabbit hole

Now, how to write a test? WinDev has built in testing capabilities, and somewhere along the line I'd noted that it was possible to create a test of a procedure. 

I'm big on automated tests. I mean really hugely big, and I'm really happy to see that WinDev has built in support. In particular, I really like testing business logic, because if the underlying business logic is good, the UI stuff is that much easier to sort out. 

So what I wanted to do was create a unit test to verify my assumptions about string slicing. 

Step one - create a global procedure. Yesterday I glibly noted that you could do so from the Project Explorer, but I hadn't actually tried it. 

First, I right-clicked on the Procedures node and selected New set of procedures. I typed a name for my set, clicked the check mark, and my Procedure Explorer display got mucked up. I neglected to take a screen shot, but essentially the explorer display didn't redraw correctly and I couldn't get a right-click option to create a new procedure. I restarted WinDev and was able to add a new procedure set, and then I could add a new procedure. I called it CreateAString_ReplaceASlice_VerifyResult().

Next I right-clicked on the procedure and selected Create a unit test. And this is what I got:

I didn't find the "Tests of the set of procedures Test_procedures" window terrifically helpful. I wanted to verify that the procedure returned a true value. 

For fun I tried running the test. I got this:

Eventually I discovered that if I right-clicked on the test in what I will call the Test Explorer I got some more useful options.

The Description brought up this window:

I still wasn't sure what Controller1 was supposed to be. So I had a look at the Code (via the previously shown context menu):

 

Ah, so Controller1 is just the return value. But the name Controller1 doesn't signify anything to me, so I renamed it to ReturnValue:

When I tried to run the test I got a compile error - I had to go into the unit test source code and change

Controller1=CreateAString_ReplaceASlice_VerifyResult() 

to

ReturnValue=CreateAString_ReplaceASlice_VerifyResult()

The test compiled, but failed:

Apparently I needed to create at least one test iteration and set the expected return value. I clicked on the Test Data tab, then on the + button to add an iteration. I set the ReturnValue to True.

After all of these changes, when I clicked on the Run test button nothing seemed to happen. Finally I went to the project dashboard, clicked on Tests, then on Start, and the test ran and passed!

After all that I've only advanced on page in the tutorial, to page 57. But being able to create and run unit tests on individual procedures is a big step forward and well worth the diversion.