To have proper data in place can be very hard when testing applications. Not only you need different data sets to test different scenarios and equivalent classes, but also providing combinations that can be fundamental to catch bugs before they actually going to the production environment.
Additionally, GeneXus applications are commonly data-intensive apps, which means that your tests will not only need a combination of data input but some data configured in your database to let tests run properly.
Mocking database is a technique that allows you to set desired database state (for different tables) in your tests in order to let specific data-sets ready for future tests execution. Using this technique you can focus on getting the test data-sets ready once (in a real database), and then use it on different test phases regarding of the environments by using mocking. In other words, Database Mocking is a simulation of a database with few records.
Mocking works by recording data (sqls / results) used for a test by listening for all queries and responses during recording stage. That information is stored (as mocking data) and will be used in all future executions of the test in different enviroments. During the recording, the queries are stored in order (order is relevant) so it is expected that test will run the querys in the same order that was recorded. As a consequence, if over the time the tests navigation changes or querys are different, mocking data will need to be recorded again.
In case that during test execution, the tests needs some data that was not recordered during recording stage, that query will use real database datasources to get the answer.
To start recording stage click on "Tests Explorer" panel located in the right side menu and right-click over a Unit Test to select the option "Record Mocking Data".
Warning: This will run the test case you've selected using the your current data-sources / databases. Finnaly, once the test ends, mocking data will be stored in a file associated with the test using the name of it. As a result, after having associated mocking data on a test, every time it runs it will use that previously recodered data without using the database.
Mocking is currently available only for .Net Enviroments. (Java is expected to be released over GeneXus 16 U3)
Current mocking data of a test is saved in a .json file in the web folder of your environment. For example, if you record data for the test "myTest", you will find a "myTest_mockingData.json" over <directoryKB>/<dirEnvironment>/web, containing recoded data that will be used in future executions. Therefore, to stop using mocking data for a test you need to delete the file.
When the tes name is changed, mocking filename should also be changed to match.
This documentation is being constructed, since this feature is still not released. Check the roadmap here.