Mongo Context varibale - Is it possible to use it throughout the test suite
Greetings,
While working with MondoDB using gmongo (groovy wrapper), we open connection using mongoDB context, something like this:
def mongoClient = new MongoClient( new ServerAddress(dbServer), Arrays.asList(credentials) ) context.gmongo = new GMongo( mongoClient ) context.mongoDB = context.gmongo.getDB(dbDatabase)
In my current framework, I open connection and close it everytime I need to do something with mongodb.
I am trying to somehow define the context once globally and use the variable to access mongodb throughout the test suite.
Is there any way to do it ?
Any help would be much appreciated.
You can set context variables in Project or TestSuite setup scripts which will then be accessible by anything under it. While I have not used this for database connections, I have stored other variables this way.
A word of warning! If for example a test case relies on something defined in a project setup script, you will always have to run from the project level. I ran into problems of not just being able to run a single test case. Now I always try to make my test cases self contained.