7

Quick Start

 3 years ago
source link: https://tsqlt.org/user-guide/quick-start/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Quick Start

Okay! You read a little about tSQLt – you want to try it out! Now what? Here is the quickest way to get going:

Downloading tSQLt and Installing the Examples

1. Download tSQLt (Button in the sidebar)
2. Unzip the file to a location on your hard drive.
3. Execute the PrepareServer.sql file.

PrepareServer.sql automatically enables CLR and installs a server certificate that allows the installation of the tSQLt CLR.
There is no need to disable strict CLR security on the server nor do you need to modify database security settings.
Executing the script requires SA permission, but needs to be done only once per server.

4. Execute the Example.sql file from the zip file to create an example database (tSQLt_Example) with tSQLt and test cases.
5. See below for installing tSQLt into your own development database.

Executing the Examples

1. Open a new Query Editor window.
2. Execute the following script to run all the example tests:

EXEC tSQLt.RunAll

3. You will see the following output in the results window:

[AcceleratorTests].[test ready for experimentation if 2 particles] failed: Expected: <1> but was: <0>
 
+----------------------+
|Test Execution Summary|
+----------------------+
 
|No|Test Case Name                                                                                            |Result |
+--+----------------------------------------------------------------------------------------------------------+-------+
|1 |[AcceleratorTests].[test a particle is included only if it fits inside the boundaries of the rectangle]   |Success|
|2 |[AcceleratorTests].[test a particle within the rectangle is returned with an Id, Point Location and Value]|Success|
|3 |[AcceleratorTests].[test a particle within the rectangle is returned]                                     |Success|
|4 |[AcceleratorTests].[test email is not sent if we detected something other than higgs-boson]               |Success|
|5 |[AcceleratorTests].[test email is sent if we detected a higgs-boson]                                      |Success|
|6 |[AcceleratorTests].[test foreign key is not violated if Particle color is in Color table]                 |Success|
|7 |[AcceleratorTests].[test foreign key violated if Particle color is not in Color table]                    |Success|
|8 |[AcceleratorTests].[test no particles are in a rectangle when there are no particles in the table]        |Success|
|9 |[AcceleratorTests].[test status message includes the number of particles]                                 |Success|
|10|[AcceleratorTests].[test we are not ready for experimentation if there is only 1 particle]                |Success|
|11|[AcceleratorTests].[test ready for experimentation if 2 particles]                                        |Failure|
-------------------------------------------------------------------------------
Msg 50000, Level 16, State 10, Line 1
Test Case Summary: 11 test case(s) executed, 10 succeeded, 1 failed, 0 errored.
-------------------------------------------------------------------------------

4. Notice that one test is failing. Click here continue on to fix the failing test and add your own tests.
5. You may also wish to assign tSQLt.RunAll to a keyboard shortcut so you can run your tests easily.

Installing to Your Development Database

Now it is time to write unit tests against your own code. tSQLt should be installed into your development database.

To install, execute the tSQLt.class.sql script (included in the zip file) in your development database.

Note: tSQLt should never be installed in production.

Learning More

1. Check out the Tutorial on Unit Testing in SQL Server with tSQLt for quick examples of the core features.
2. Join the discussion:

3. Discover more details on tSQLt’s features in the Reference section of the User Guide


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK