Mock data set based on view

Related products: Software Factory

At this moment the Software Factory does not support creating mock data based on views. This means that functionality that is based on a view cannot be covered by unit tests. I’m not sure if it is, but a work around could be to fill all the tables on which the view depends on with mock data, but this could get very time consuming and not necessary if you don’t want to test the view itself. 

If it would be possible to create mock data based on views, then the Software Factory can for example:

  • Rename the existing view
  • Create a mock table based on this view, with the original name
  • add the mock data

 After the unit test has completed, the mock table can be dropped and the view renamed to it’s original name.

Maybe the solution above is a bit blunt. The following solution might be cleaner:

  • Alter the current view and generate a query which unions the mock data values. 
  • Test the unit test
  • Alter the view and add the original views sql query statement.

NewOpen

Hi Bram,

Could this be an alternative?: 

Nevertheless, good idea 😄


This would add ALOT of complexity in our situation as we are using external tables (and views on top of those). 


Hi @BramG,

In the 2023.2 release, we will provide the option to add a preparation query to a mock data set. With this, you can programmatically enhance mock data or other database objects such as views or functions via alter-statements. This query was already available for unit tests.

When running a unit test, the preparation query for a mock data set will be executed after all the mock tables have been prepared but before the preparation query for the unit test is executed.

Also see:

With this, I think you can accomplish the same things (and more) as with your original idea. Do you agree?


OpenNeeds feedback

Hi @Jeroen van den Belt , I like this idear.
But I think what it would make it more powerfull is that the SF can generate an alter statement for the view with mock data set, because all the benefits of the SF will be in place, renaming a column for example.

And I think it would be very beneficial to know from within the SF that a view is being altered for a unit test, so the SF can also generate the alter statement to get the view back to the original state.

How is your ‘view’ on this?


Hi @Robbert van Tongeren,

I think that is a fair argument. I will add this idea to our backlog and will change the status accordingly.


Needs feedbackOn the backlog

On the backlogWorking on it!

Working on it!Next release

Next releaseCompleted