We use the Robot Framework for some time for automated software tests in our projects. In addition, a few of my colleagues deal with the NoSql Database MongoDB (Tutorial MongoDB). The document management solution Center-Device (Start-Up of Codecentric AG) also uses MongoDB in the backend (Center-Device Architecture-Overview). So I thought, it’s time for a new Robot-Library: robotframework-mongodblibrary. The version 0.2.1 is ready for download on GitHub (Keyword-Documentation).
The library is written in Java (Jython) and uses internally the MongoDB Java Driver. Despite limited experience, programming the library was very easy. Thx for the great MongoDB-Documentation
the first robot test
*** Settings *** Library de.codecentric.robot.mongodblibrary.keywords.MongodbLibrary Test Setup Setup MongoDB *** Test Cases *** should insert given document Insert Document myCollection {say : 'Hello MongoDb!'} Collection Should Exist myCollection Document Should Exist myCollection {say : 'Hello MongoDb!'} *** Keywords *** Setup MongoDB Connect To Server localhost 27020 robotdb1 Drop Database robotdb1 |
Robot Remote Library
The robot remote library is also on board Then you can start the library as a separate server. This is very useful if you want to use python instead of jython in the main test suite.
*** Settings *** Library Remote http://localhost:8270 Test Setup Setup MongoDB *** Test Cases *** should insert given document Insert Document myCollection {say : 'Hello MongoDb!'} Collection Should Exist myCollection Document Should Exist myCollection {say : 'Hello MongoDb!'} *** Keywords *** Setup MongoDB Connect To Server localhost 27020 robotdb1 Drop Database robotdb1 |
Before starting the tests you need to start the server by the folowing shell command:
java -jar build/libs/robotframework-mongodblibrary-0.2.1-with-dependencies.jar --port 8270 |
MongoDB-Server Embedded
Since the 0.2-Version there is a keyword that starts a MongoDB-Server (of a given Version) within the tests. This is done by the Embedded MongoDB Library. The keyword downloads the server from the MongoDB-Webpage, extracts this to the home directory und starts the MongoDB Daemon in a seperate oprating system process (MongoDB is written in C++). At the end of test the daemon should be terminated by the keyword Shutdown Embedded, that’s a clean shutdown of the database.
*** Settings *** Library de.codecentric.robot.mongodblibrary.keywords.MongodbLibrary Suite Setup Startup Embedded 2.4.4 Suite TearDown Shutdown Embedded Test Setup Setup MongoDB *** Test Cases *** should insert given document Insert Document myCollection {say : 'Hello MongoDb!'} Collection Should Exist myCollection Document Should Exist myCollection {say : 'Hello MongoDb!'} *** Keywords *** Setup MongoDB Connect To Server localhost 27020 robotdb1 Drop Database robotdb1 |
One of the main benefits of the server integration is the resulting clarity of the Robot-Logs. The log messages of the MongoDB Server are written to the Robot-Log and can directly assigned to the keywords:
Usage in other testing frameworks
The library has no dependencies to the robotframework, so you can also use the library with other testing frameworks (e.g. Junit, JBehave). For this approach there is another download version without dependencies.
have fun with the library