What are the rules of a valid dataprovider?

20 views
Skip to first unread message

Jim O'Keefe

unread,
Jul 20, 2016, 6:55:57 PM7/20/16
to mxunit
Here's my code:
 data1 = [{logical_delete_date = '2016-01-01 10:10:10', somethingelse = 0},{logical_delete_date = '2016-01-01 10:10:10', somethingelse = 'Hello World'}];
 data2
= [{something = '2016-01-01 10:10:10', somethingelse = 0},{something = '2016-01-01 10:10:10', somethingelse = 'Hello World'}];
 sortByUpdateData
= [
 
{info: data1, expectedupdate: 2, expectedInsert: 0},
 
{info: data2, expectedupdate: 0, expectedInsert: 2}
 
];
// alternate code that produced same error:
/*
sortByUpdateData = [
{data: [{logical_delete_date = '2016-01-01 10:10:10', somethingelse = 0},{logical_delete_date = '2016-01-01 10:10:10', somethingelse = 'Hello World'}], expectedUpdate: 2, expectedInsert: 0},
{data: [{something = '2016-01-01 10:10:10', somethingelse = 0},{something = '2016-01-01 10:10:10', somethingelse = 'Hello World'}], expectedUpdate: 0, expectedInsert: 2}
];
*/


 
public void function test_sortByUpdate(required any info, required any expectedupdate, required any expectedInsert) mxunit:dataprovider="sortByUpdateData" {
 
local.action = CUT.sortByUpdate(arguments.data);
 actualUpdate
= arrayLen(local.action.update);
 actualInsert
= arrayLen(local.action.insert);
 assertEquals
(actualUpdate, arguments.expectedUpdate);
 assertEquals
(actualInsert, arguments.expectedInsert);
 
}
I no longer get the invalid dataprovider error, but it seems like this is too complicated/nested. I previously had data1 & data2 inline, and that resulted in the same error: The EXPECTEDUPDATE parameter to the test_sortByUpdate function is required but was not passed in. 

Marc Esher

unread,
Jul 23, 2016, 2:19:01 PM7/23/16
to mxu...@googlegroups.com
Hey Jim,

Pretty sure I see what's going on here.

The way dataproviders work is that for each item in the provider,
it'll inject that item as a single argument.

So since your data provider is an array of structs, your test function
will just receive that struct as its only argument. You can see
exactly what you're getting with something like this:

function test_sortByUpdate(data) mxunit:dataprovider="sortByUpdateData" {
debug(data)
}

which will dump out what you're getting.

Let me know if that helps.

Marc
> --
> You received this message because you are subscribed to the Google Groups
> "mxunit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mxunit+un...@googlegroups.com.
> To post to this group, send email to mxu...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mxunit.
> For more options, visit https://groups.google.com/d/optout.

Jim O'Keefe

unread,
Jul 25, 2016, 3:24:29 PM7/25/16
to mxunit
Hi Marc, I thought I understood what you were saying but nothing was working. Then I realized you had changed the signature of my test function to have only one argument. 

'function test_sortByUpdate(data) mxunit:dataprovider="sortByUpdateData" { '
as opposed to ' public void function test_sortByUpdate(required any info, required any expectedupdate, required any expectedInsert) mxunit:dataprovider="sortByUpdateData" {.'

Then everything fell into place and I realized that a dataprovider will pass in one "thing" at a time so a function that uses a dataprovider should accept only one argument. That one "thing" can be many layers deep but it is still just one argument. Once I had this insight I reread your words and you had clearly said as much but it just hadn't clicked for me. Thanks for your continued support of this project in general, and answering my question in particular.

Marc Esher

unread,
Jul 26, 2016, 1:58:09 PM7/26/16
to mxu...@googlegroups.com
Glad you got it working!
Reply all
Reply to author
Forward
0 new messages