I have a question about unit tests. We're currently working on getting to grips with this subject. But I'm kinda stuck on one specific unit test. I have a default that I want to test. It is a simple one that removes spaces from a string, as follows:
if @cursor_from_col_id = '[field]' and @[field] is not null begin set @[field] = REPLACE(@[field], ' ', ''); end;
But now I'm lost when adding the input parameters for the unit test. I'm choosing 'postal_code’ as a parameter with input '1234 AB’. But when I run the test it just returns '1234 AB’ (so it failed). I also tried adding 'cursor_from_col_id’ with input 'postal_code’ as an input parameter, but that also didn't work.
Looking forward to your answer!
Page 1 / 1
Hi Marcel,
As you describe it, it should work fine. So I'm wondering what the missing context is.
If I understood you well, you are trying to do the following:
Code: if @cursor_from_col_id = 'postal_code’ and @postal_code is not null begin set @postal_code = REPLACE(@postal_code, ' ', ''); end;
This situation should indeed be an expected success. Are you sure that there is nothing else altering the code, and that the default procedure code is executed on the database?
I'll need to look into this case to figure out what causes the problem. It indeed seems like an easy unit test scenario.
With kind regards,
Serhat Sahin
Hello Serhat,
I let it simmer for the weekend and decided to have a look at it again this morning. But no matter how I look at it, I can't seem to find anything wrong with it. So I'm hoping you can have a more in depth look at it. I think all the info is in the story, but if you need anything else, please let me know!
Many thanks in advance!
BTW: I've obviously checked that the default is working in the application
Just to be sure, I have added screenshots FYI.
Hope this helps!
Did you take a look at what the unit tests actually executes? The debugger in the SF has somewhere a process where it translates the unit test to sql code. This might give you more information / insights on what's happening.
Thanks for your reply. It is difficult to see what I'm looking for. Every time I run the unit test I get a couple of processes (but they all sort of look the same). The following seems to be the essential of it:
select @cursor_to_col_id as cursor_to_col_id, @zba_portaal_berichten_overig_client_id as zba_portaal_berichten_overig_client_id, @zba_portaal_berichten_overig_bericht_id as zba_portaal_berichten_overig_bericht_id, @bsn as bsn, @geboortedatum as geboortedatum, @geslacht as geslacht, @achternaam as achternaam, @voorvoegsel as voorvoegsel, @voorletters as voorletters, @commentaar as commentaar;
Notice the double single quotes around the values (these wouldn't work in SQL Server) and the fact that @cursor_from_col_id is not included in the SELECT. But again, not sure if this is a problem.
Thanks for all replies.
You've picked the right piece of code from the debug. Even the debug seems okay…
Just to clarify, the double quotes are needed to execute the whole as a string (so double quotes will become a single quote), so you can ignore those and replace them with single quotes in SQL Server. The select statement is selecting the output parameters. The cursor_from_col_id parameter is an input parameter only, that's why it's excluded in the select statement.
Could you check your private messages for me? I've sent you a message to help you in this matter and try to figure out what's wrong with this whole scenario.
Serhat and I will look into it together. After that, I'll post our findings below this story for others.
Today Serhat looked at it. The fact that it didn't work was because I used a field for unit testing (postal_code) that I didn't use in the application. In the application I used the field 'initials’. So the lesson here: only unit test a dynamic default on columns that you also use in the application. Thanks Serhat for the help!