Q:

Run Test Suites with a single Database connection

I was asked a question which i did not know the answer.
He asked me.

I have 5 test suites ( each test suite would have many test cases written in Selenium )
I want to open a database only once and run all the test suites.

How would i do that?
Please help,
Thanks,
JB.

A:

singe31 is correct.  I have done this before to accomplish this exact thing.
c#
    public class DataAccessObject
    {
        private static DataAccessObject _dataObject = null;
        private static readonly object _lock = new object();
        public static DataAccessObject dataObj {
            get {
                lock (_lock) {
                    if (_dataObject == null) {
                        _dataObject = new DataAccessObject();
                    }
                    return _dataObject;
                }
            }
        }

        private DataAccessObject()
        {
            //populate your _dataObject in here
        }
    }

Then in your code you can make an instance of your DataAccessObject equal to the public property private DataAccessObject _dataObject = DataAccessObject.dataObj
This will hit the property and pull the in memory read only value and assign it to your local variable.  If it already exists then it just pulls what's in memory, otherwise it will instantiate a new instance and return it and the next test will get the in memory one.
The _lock is there for threading purposes if you want 2 at the same time.  It will lock access to one and cause the other to wait until it is finished before starting.  That way you only instantiate once instead of risking corruption by doing one and overwriting it right afterwards.

