I have not been able to find the solution of this problem anywhere:
I am building a class PrivateHelper that provides methods to access
private members and invoke private methods, to be used for testing.
In a particular test case, an array is passed to the Method Under Test,
and then that MUT performs a ReDim on the array. The test code then
needs to check the array, but the effect of the ReDim statement does
not propagate to the test code. As long as no ReDim is done, there are
no problems and all changes to the array are visible for the test code.
This is a simplified sketch of how I have done (The PrivateHelper class
is left out):
Sub testCase()
Dim testArray = New Byte() {1, 1}
'setup methodInfo for method "changeArray" in class myObject
methodInfo.Invoke(myObject, New Object() {testArray})
'check if testArray(0) = 2 THIS CHECK FAILS
End Sub
Class myObject
Sub changeArray(ByRef testArray As Byte())
ReDim testArray(3)
testArray(0) = 2
End Sub
End Class
I am not allowed to do any changes in the myObject class. Is there a
way around this problem?