Invoke-DlmDatabaseTests
Published 13 J 2016
Invoke-DlmDatabaseTests
Runs the tSQLt tests on a database schema.
Syntax
Invoke-DlmDatabaseTests [-InputObject] <Object> [-IncludeTestData] [-SQLDataGeneratorProject <string>] [-RunOnly <string>] [-TemporaryDatabaseServer <DatabaseServerConnection>] [-SQLCompareOptions <string>] [-QueryBatchTimeout <int>] [<CommonParameters>] |
Description
The Invoke-DlmDatabaseTests cmdlet executes the tSQLt tests on a database schema. The schema can be a scripts folder, a NuGet package or a database. It creates a TestResults object that represents the results of the tests.
If you use a database connection as the input, the cmdlet will run the tests directly on the specified database.
If you use a scripts folder or a NuGet package as the input, by default the cmdlet will create a temporary database on LocalDB to run the tests on. Alternatively, you can use the TemporaryDatabaseServer parameter to specify a SQL Server instance to create the temporary database on. This is useful if your database uses features that aren't supported by LocalDB, such as Full-Text Search. If you don't want to use LocalDB and don't have permission to create a database on the SQL Server instance, you can use the TemporaryDatabase parameter to specify an existing database.
Parameters
-InputObject
<System.Object>
The schema to run the tSQLt tests on.
This can be a scripts folder, a NuGet package or a database connection. This can be:
- a Database Connection object created by the New-DlmDatabaseConnection cmdlet
- a database connection string
- a path for a NuGet package or .zip file. This must contain a scripts folder located at db\state
- a Database Package object produced by the New-DlmDatabasePackage cmdlet
- a path for a scripts folder, created by SQL Compare or from your SQL Source Control database repository
Aliases | None |
Required? | true |
Position? | 0 |
Default Value | None |
Accept Pipeline Input | true (ByValue) |
Accept Wildcard Characters | false |
-IncludeTestData
<System.Management.Automation.SwitchParameter>
Use this parameter to add random data to the test database.
You can have more control over the data being added, by using the SQLDataGeneratorProject parameter instead.
This parameter will be ignored if the InputObject is a database connection.
Aliases | None |
Required? | false |
Position? | named |
Default Value | False |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
-SQLDataGeneratorProject
<System.String>
Use this parameter to specify a SQL Data Generator project file (.sqlgen) that defines the data to be added to the test database.
To add random data to the test database, use the IncludeTestData parameter instead.
This parameter will be ignored if the InputObject is a database connection.
Aliases | None |
Required? | false |
Position? | named |
Default Value | None |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
-RunOnly
<System.String>
Use this parameter to run a specific test or a specific test suite. If you don't use this parameter, every test will be run.
Aliases | None |
Required? | false |
Position? | named |
Default Value | None |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
-TemporaryDatabaseServer
<RedGate.SQLRelease.Compare.SchemaSources.DatabaseServerConnection>
The connection string for the temporary database server used for testing. For example, 'Data Source=TempServer01'.
This parameter will be ignored if the InputObject is a database connection.
By default, SQL Release uses LocalDB for the temporary database. However there may be some features in your database that aren't supported by LocalDB (for example, Full-Text Search). In this case, or if LocalDB is not present, use this parameter to specify an alternative SQL Server instance for the temporary database.
Using this option, SQL Release will create a temporary, randomly-named database on the specified SQL Server instance.
You can't use this parameter in addition to the TemporaryDatabase parameter.
Aliases | None |
Required? | false |
Position? | named |
Default Value | None |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
-TemporaryDatabase
<RedGate.SQLRelease.Compare.SchemaSources.DatabaseConnection>
The details of the temporary database used for testing. This can be:
- a database connection object that contains the connection details for a database. See New-DlmDatabaseConnection for details.
- a database connection string. For example, 'Data Source=TempServer01;Initial Catalog=TempDatabase01'.
This parameter will be ignored if the InputObject is a database connection.
By default, SQL Release uses LocalDB for the temporary database. If you don't want to use LocalDB and don't have permission to create a database on the SQL Server instance, use this option to specify an existing database to use for the temporary copy of the database.
You can't use this parameter in addition to the TemporaryDatabaseServer parameter.
Aliases | None |
Required? | false |
Position? | named |
Default Value | None |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
-SQLCompareOptions
<System.String>
Specifies the SQL Compare options to use when creating the test database. SQL Release applies a default set of options, listed below. To include additional options, specify a comma-delimited list of the option names (eg 'IgnoreComments, ObjectExistenceChecks'). To turn off a default option, precede the option name with a minus sign (eg '-ForceColumnOrder').
This parameter will be ignored if the InputObject is a database connection or if the value specified is either $null or empty.
By default, the following Compare options are used:
- ConsiderNextFilegroupInPartitionSchemes
- DecryptPost2KEncryptedObjects
- DoNotOutputCommentHeader
- ForceColumnOrder
- IgnoreCertificatesAndCryptoKeys
- IgnoreDatabaseAndServerName
- IgnoreUsersPermissionsAndRoleMemberships
- IgnoreUserProperties
- IgnoreWhiteSpace
- IgnoreWithElementOrder
- IncludeDependencies
- ThrowOnFileParseFailed
- UseCompatibilityLevel
See http://www.red-gate.com/sqlreleasecompareoptions for a complete list of SQL Compare options supported by SQL Release.
Aliases | None |
Required? | false |
Position? | named |
Default Value | None |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
-QueryBatchTimeout
<System.Int32>
The execution timeout, in seconds, for each batch of queries when creating the test database. The default value is 30 seconds. A value of zero indicates that no execution timeout will be enforced.
This parameter will be ignored if the InputObject is a database connection.
Aliases | None |
Required? | false |
Position? | named |
Default Value | 30 |
Accept Pipeline Input | false |
Accept Wildcard Characters | false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see http://technet.microsoft.com/en-us/library/hh847884.aspx.
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
- System.Object
The schema to run the tSQLt tests on.
This can be a scripts folder, a NuGet package or a database connection. This can be:
- a Database Connection object created by the New-DlmDatabaseConnection cmdlet
- a database connection string
- a path for a NuGet package or .zip file. This must contain a scripts folder located at db\state
- a Database Package object produced by the New-DlmDatabasePackage cmdlet
- a path for a scripts folder, created by SQL Compare or from your SQL Source Control database repository
Return values
The output type is the type of the objects that the cmdlet emits.
- RedGate.SQLRelease.Compare.SchemaTesting.TestResults
Examples
---------- EXAMPLE 1 ----------
|
This example shows how to use the Invoke-DlmDatabaseTests cmdlet to run tSQLt tests on a database.
The output will be a TestResults object, which contains the test results.
---------- EXAMPLE 2 ----------
|
This example shows how to use the Invoke-DlmDatabaseTests cmdlet to run tSQLt tests for a scripts folder.
The cmdlet will use LocalDB to run the tests on.
---------- EXAMPLE 3 ----------
|
This example shows how to add random test data before the tests are run.
---------- EXAMPLE 4 ----------
|
This example shows how to add test data defined by a SQL Data Generator project file (.sqlgen).
---------- EXAMPLE 5 ----------
|
This example shows how to run the single test "[SQLCop].[test Unnamed Constraints]".
To run all tests in a single test suite, use the RunOnly parameter to specify the name of the test suite. For example: "[SQLCop]".
---------- EXAMPLE 6 ----------
|
This example shows how to specify a SQL Server instance for the temporary database, instead of using LocalDB.
This is useful if you don't want to use LocalDB because your database uses features that aren't supported by LocalDB, such as Full-Text Search.
---------- EXAMPLE 7 ----------
|
This example shows how to specify an existing SQL Server database to use as the temporary database, instead of using LocalDB.
This is useful if you don't want to use LocalDB and you don't have permission to create a database on the SQL Server instance.
---------- EXAMPLE 8 ----------
|
This example shows how to specify SQL Compare options to use when creating the test database.
In this example, the $options variable is used to specify that the IgnoreComments and ObjectExistenceChecks options should be included in addition to the default set of SQL Compare options used by this cmdlet. The minus sign before IgnoreUserProperties indicates that this default option will be turned off.