Make prefix 'SQLTest' configurable

Oct 17, 2011 at 3:09 PM

Currently the stored procedures reuire to have the prefix SQLTest.

Since we only use lower case object names and use prefixes like t_ for tables, p_ for procedures, f_ for functions, etc. it would be more logical to use ut_ as prefix for the unit tests.

It would be nice if this setting could be stored somewhere and used.

Oct 18, 2011 at 1:30 PM

I implemented this myself. I used the TSTParameters table to store the setting. I added a new parameter 'UnitTestPrefix', but only allowed this to be defined at TestSession level and for scope 'All'. I did add an option to use a global setting, by using TestSessionId = 0. This to prevent to having to define a TSTConfig procedure for all our databases.

I changed all procs that now use the literal 'SQLTest_', either by passing the prefix to it or by determining the prefix inside the proc via the function below.

Changed procs:
- Altered Utils.SetConfiguration to be able to set the setting via TSTConfig
- Calculated @UnitTestPrefix inside 'Internal.PrepareTestSessionInformation'
- Added @UnitTestPrefix as input parameter to: 'Internal.SuiteExists' and 'Internal.AnalyzeSprocName'

I'm very willing to provide the code to codeplex so that this feature becomes a available for a future release. But it seems I'm not able to attach files? Or can I mail the updated script to someone?

New Function: SFN_UnitTestPrefix
-- =======================================================================
-- FUNCTION SFN_UnitTestPrefix
-- Specifies the prefix to use for unit test procedures.
-- =======================================================================
CREATE FUNCTION Internal.SFN_UnitTestPrefix(@TestSessionId int) RETURNS VARCHAR(100)
AS
BEGIN

   DECLARE @UnitTestPrefix varchar(100)
  
   SET @UnitTestPrefix = 'SQLTest_' -- Default value
   -- Retrieve global value: TestSesionId = 0 and Scope = 'All'
   SELECT @UnitTestPrefix = TSTParameters.ParameterValue
   FROM Data.TSTParameters
   WHERE
      TestSessionId = 0
      AND ParameterName  = 'UnitTestPrefix'
      AND Scope = 'All'
   -- Retrieve TestSession specific value. Will override the global scope
   SELECT @UnitTestPrefix = TSTParameters.ParameterValue
   FROM Data.TSTParameters
   WHERE
      TestSessionId = @TestSessionId
      AND ParameterName  = 'UnitTestPrefix'
      AND Scope = 'All'

   RETURN @UnitTestPrefix
END
GO

Coordinator
Oct 31, 2011 at 9:42 PM

I will accommodate your request in the next release.

I am not crazy about making the prefix configurable. I feel that to implement it is more complicated than it is worth. Allowing different people to set their own prefix has indeed some small value but can also cause confusion. However you are not the first person to make this request so I am going to include this feature in the next release. For now it will be “undocumented” but that may change later.

The implementation is a bit more complicated than you show so my implementation will differ from your code. One issue is that ideally the prefix has to be set per test database. Consider the scenario where in an enterprise two teams consolidate their TST test sever. One team uses one prefix and another uses a different prefix. The consolidated TST database should support both. There is the issue of test automation for TST itself (TSTCheck.bat). Also the fact that this setting should be preserved when the user upgrades to a new version.

Before releasing I am going to send you a private build to try it out.

 

Coordinator
Nov 1, 2011 at 6:10 AM
Edited Nov 1, 2011 at 6:10 AM

tlambrec, see the TST_1_8.zip unde the issue you created: "Make prefix 'SQLTest_' configurable". It is fully tested, I am curios if you have any feedback. I will release V 1.8 in a few weeks with a few more minor things in it.

Step 1. Unpack TST_1_8.zip

Step 2. Install TST V 1.8 by running TST.bat

Step 3. Run 
TST.bat /set NULL  SqlTestPrefix ut_
This assuming that your preffix is "ut_" and is global per all test databases. To set the prefix for one test database run:
TST.bat /set TestDbName SqlTestPrefix ut_

Step 4. Run the test runners.

Note: the prefix setting will be preserved when you will install the next version but you can alway run TST.bat /set ...

 

Coordinator
Nov 13, 2011 at 8:02 AM

Implemented in V 1.8.
V 1.8 was just released.