Skip to content

Commit d853ac4

Browse files
Build script changes for enhanced testing experience (#1382)
1 parent ab8ca76 commit d853ac4

File tree

5 files changed

+143
-45
lines changed

5 files changed

+143
-45
lines changed

BUILDGUIDE.md

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This document provides all the necessary details to build the driver and run tes
55
## Visual Studio Pre-Requisites
66

77
This project should be built with Visual Studio 2019+ for the best compatibility. The required set of components are provided in the below file:
8+
89
- **Visual Studio 2019** with imported components: [VS19Components](/tools/vsconfig/VS19Components.vsconfig)
910

1011
Once the environment is setup properly, execute the desired set of commands below from the _root_ folder to perform the respective operations:
@@ -19,6 +20,11 @@ msbuild
1920
# Both .NET Framework (NetFx) and .NET Core drivers are built by default (as supported by Client OS).
2021
```
2122

23+
```bash
24+
msbuild -t:clean
25+
# Cleans all build directories.
26+
```
27+
2228
```bash
2329
msbuild -p:Configuration=Release
2430
# Builds the driver in 'Release' Configuration for `AnyCPU` platform.
@@ -29,11 +35,6 @@ msbuild -p:Platform=Win32
2935
# Builds the .NET Framework (NetFx) driver for Win32 (x86) platform on Windows in 'Debug' Configuration.
3036
```
3137

32-
```bash
33-
msbuild -t:clean
34-
# Cleans all build directories.
35-
```
36-
3738
```bash
3839
msbuild -t:restore
3940
# Restores Nuget Packages.
@@ -77,37 +78,85 @@ msbuild -t:BuildTestsNetCore -p:TestSet=1
7778
# Build a subset of the manual tests. Valid values: '1', '2', '3', 'AE'. Omit to build all tests.
7879
```
7980

80-
## Run Functional Tests
81+
## Running Tests
82+
83+
There are 2 ways to run tests, using MsBuild or Dotnet SDK.
84+
85+
### Running from Build.proj
86+
87+
```bash
88+
msbuild -t:RunFunctionalTests
89+
# Run all functional tests for *default* target framework (.NET Core 3.1).
90+
```
91+
92+
```bash
93+
msbuild -t:RunManualTests
94+
# Run all manual tests for *default* target framework (.NET Core 3.1).
95+
```
96+
97+
```bash
98+
msbuild -t:RunTests -p:configuration=Release
99+
# Run both functional and manual tests for *default* target framework (.NET Core 3.1).
100+
```
101+
102+
To specify custom target framework, use `TF` property:
103+
104+
```bash
105+
msbuild -t:RunTests -p:configuration=Release -p:TF=net5.0
106+
msbuild -t:RunTests -p:configuration=Release -p:TF=net48
107+
# Runs tests for specified target framework.
108+
# TargetNetCoreVersion and TargetNetFxVersion are not to be used with TF property, they will take precedence over TF if provided.
109+
```
110+
111+
To capture test and code coverage results in a custom directory:
112+
113+
```bash
114+
msbuild -t:RunTests -p:ResultsDirectory=MyDirectory
115+
# Runs tests with test and code coverage results placed in provided results directory.
116+
# Default results directory is "TestResults".
117+
```
118+
119+
Other properties can be set alongside as needed.
120+
121+
### Running using Dotnet SDK (traditional)
122+
123+
#### Run Functional Tests
81124

82125
- Windows (`netfx x86`):
126+
83127
```bash
84128
dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="Win32" -p:Configuration="Release" -p:TestTargetOS="Windowsnetfx" --no-build -v n --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests"
85129
```
86130

87131
- Windows (`netfx x64`):
132+
88133
```bash
89134
dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="x64" -p:Configuration="Release" -p:TestTargetOS="Windowsnetfx" --no-build -v n --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests"
90135
```
91136

92137
- AnyCPU:
93138

94139
Windows (`netcoreapp`):
140+
95141
```bash
96142
dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Windowsnetcoreapp" --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests"
97143
```
98144

99145
Unix (`netcoreapp`):
146+
100147
```bash
101148
dotnet test "src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Unixnetcoreapp" --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonlinuxtests&category!=nonuaptests"
102149
```
103150

104-
## Run Manual Tests
151+
#### Run Manual Tests
152+
153+
### Pre-Requisites for running Manual tests
105154

106-
### Pre-Requisites for running Manual tests:
107155
Manual Tests require the below setup to run:
108-
* SQL Server with enabled Shared Memory, TCP and Named Pipes Protocols and access to the Client OS.
109-
* Databases "NORTHWIND" and "UdtTestDb" present in SQL Server, created using SQL scripts [createNorthwindDb.sql](tools/testsql/createNorthwindDb.sql) and [createUdtTestDb.sql](tools/testsql/createUdtTestDb.sql). To setup an Azure Database with "NORTHWIND" tables, use SQL Script: [createNorthwindAzureDb.sql](tools/testsql/createNorthwindAzureDb.sql).
110-
* Make a copy of the configuration file [config.default.json](src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json) and rename it to `config.json`. Update the values in `config.json`:
156+
157+
- SQL Server with enabled Shared Memory, TCP and Named Pipes Protocols and access to the Client OS.
158+
- Databases "NORTHWIND" and "UdtTestDb" present in SQL Server, created using SQL scripts [createNorthwindDb.sql](tools/testsql/createNorthwindDb.sql) and [createUdtTestDb.sql](tools/testsql/createUdtTestDb.sql). To setup an Azure Database with "NORTHWIND" tables, use SQL Script: [createNorthwindAzureDb.sql](tools/testsql/createNorthwindAzureDb.sql).
159+
- Make a copy of the configuration file [config.default.json](src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json) and rename it to `config.json`. Update the values in `config.json`:
111160

112161
|Property|Description|Value|
113162
|------|--------|-------------------|
@@ -130,36 +179,40 @@ Manual Tests require the below setup to run:
130179
|IsAzureSynpase | (Optional) When set to 'true', test suite runs compatible tests for Azure Synapse/Parallel Data Warehouse. | `true` OR `false`|
131180
|MakecertPath | The full path to makecert.exe. This is not required if the path is present in the PATH environment variable. | `D:\\escaped\\absolute\\path\\to\\makecert.exe` |
132181

133-
### Commands to run Manual Tests:
182+
### Commands to run Manual Tests
183+
184+
- Windows (`netfx x86`):
134185

135-
- Windows (`netfx x86`):
136186
```bash
137187
dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" -p:Platform="Win32" -p:Configuration="Release" -p:TestTargetOS="Windowsnetfx" --no-build -v n --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests"
138188
```
139189

140-
- Windows (`netfx x64`):
190+
- Windows (`netfx x64`):
191+
141192
```bash
142193
dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" -p:Platform="x64" -p:Configuration="Release" -p:TestTargetOS="Windowsnetfx" --no-build -v n --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests"
143194
```
144195

145-
- AnyCPU:
196+
- Windows (`netfx`):
146197

147-
Windows (`netfx`):
148198
```bash
149199
dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Windowsnetfx" --no-build -v n --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests"
150200
```
151201

152-
Windows (`netcoreapp`):
202+
- Windows (`netcoreapp`):
203+
153204
```bash
154205
dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Windowsnetcoreapp" --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests"
155206
```
156207

157-
Unix (`netcoreapp`):
208+
- Unix (`netcoreapp`):
209+
158210
```bash
159211
dotnet test "src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Unixnetcoreapp" --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonlinuxtests&category!=nonuaptests"
160212
```
161213

162214
## Run A Single Test
215+
163216
```bash
164217
dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Windowsnetcoreapp" --no-build -v n --filter "FullyQualifiedName=Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.CspProviderExt.TestKeysFromCertificatesCreatedWithMultipleCryptoProviders"
165218
```
@@ -175,11 +228,12 @@ Tests can be built and run with custom "Reference Type" property that enables di
175228

176229
> ************** IMPORTANT NOTE BEFORE PROCEEDING WITH "PACKAGE" AND "NETSTANDARDPACKAGE" REFERENCE TYPES ***************
177230
> CREATE A NUGET PACKAGE WITH BELOW COMMAND AND ADD TO LOCAL FOLDER + UPDATE NUGET CONFIG FILE TO READ FROM THAT LOCATION
178-
> ```
231+
>
232+
> ```bash
179233
> msbuild -p:configuration=Release
180234
> ```
181235
182-
### Building Tests:
236+
### Building Tests with Reference Type
183237
184238
For .NET Core, all 4 reference types are supported:
185239
@@ -203,18 +257,19 @@ msbuild -t:BuildTestsNetFx -p:ReferenceType=Project
203257
msbuild -t:BuildTestsNetFx -p:ReferenceType=Package
204258
```
205259

206-
### Running Tests:
260+
### Running Tests with Reference Type
207261

208262
Provide property to `dotnet test` commands for testing desired reference type.
209-
```
263+
264+
```bash
210265
dotnet test -p:ReferenceType=Project ...
211266
```
212267

213-
## Testing with Custom TargetFramework
268+
## Testing with Custom TargetFramework (traditional)
214269

215270
Tests can be built and run with custom Target Frameworks. See the below examples.
216271

217-
### Building Tests:
272+
### Building Tests with custom target framework
218273

219274
```bash
220275
msbuild -t:BuildTestsNetFx -p:TargetNetFxVersion=net462
@@ -228,7 +283,7 @@ msbuild -t:BuildTestsNetCore -p:TargetNetCoreVersion=netcoreapp3.1
228283
# Applicable values: netcoreapp3.1 | net5.0 | net6.0
229284
```
230285

231-
### Running Tests:
286+
### Running Tests with custom target framework (traditional)
232287

233288
```bash
234289
dotnet test -p:TargetNetFxVersion=net462 ...
@@ -244,25 +299,25 @@ dotnet test -p:TargetNetCoreVersion=netcoreapp3.1 ...
244299

245300
Managed SNI can be enabled on Windows by enabling the below AppContext switch:
246301

247-
**"Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows"**
302+
`Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows`
248303

249304
## Set truncation on for scaled decimal parameters
250305

251306
Scaled decimal parameter truncation can be enabled by enabling the below AppContext switch:
252307

253-
**"Switch.Microsoft.Data.SqlClient.TruncateScaledDecimal"**
308+
`Switch.Microsoft.Data.SqlClient.TruncateScaledDecimal`
254309

255310
## Enabling row version null behavior
256311

257312
`SqlDataReader` returns a `DBNull` value instead of an empty `byte[]`. To enable the legacy behavior, you must enable the following AppContext switch on application startup:
258313

259-
**"Switch.Microsoft.Data.SqlClient.LegacyRowVersionNullBehavior"**
314+
`Switch.Microsoft.Data.SqlClient.LegacyRowVersionNullBehavior`
260315

261316
## Enabling OS secure protocols preference
262317

263318
TLS 1.3 has been excluded due to the fact that the driver lacks full support. To enable OS preferences as before, enable the following AppContext switch on application startup:
264319

265-
**"Switch.Microsoft.Data.SqlClient.EnableSecureProtocolsByOS"**
320+
`Switch.Microsoft.Data.SqlClient.EnableSecureProtocolsByOS`
266321

267322
## Debugging SqlClient on Linux from Windows
268323

@@ -271,14 +326,17 @@ For enhanced developer experience, we support debugging SqlClient on Linux from
271326
This project is also included in `docker-compose.yml` to demonstrate connectivity with SQL Server docker image.
272327

273328
To run the same:
329+
274330
1. Build the Solution in Visual Studio
275331
2. Set `docker-compose` as Startup Project
276332
3. Run "Docker-Compose" launch configuration.
277333
4. You will see similar message in Debug window:
334+
278335
```log
279336
Connected to SQL Server v15.00.4023 from Unix 4.19.76.0
280337
The program 'dotnet' has exited with code 0 (0x0).
281338
```
339+
282340
5. Now you can write code in [Program.cs](/src/Microsoft.Data.SqlClient/tests/DockerLinuxTest/Program.cs) to debug SqlClient on Linux!
283341
284342
### Troubleshooting Docker issues
@@ -288,6 +346,7 @@ There may be times where connection cannot be made to SQL Server, we found below
288346
- Clear Docker images to create clean image from time-to-time, and clear docker cache if needed by running `docker system prune` in Command Prompt.
289347
290348
- If you face `Microsoft.Data.SqlClient.SNI.dll not found` errors when debugging, try updating the below properties in the netcore\Microsoft.Data.SqlClient.csproj file and try again:
349+
291350
```xml
292351
<OSGroup>Unix</OSGroup>
293352
<TargetsWindows>false</TargetsWindows>
@@ -310,13 +369,14 @@ dotnet test <test_properties...> --collect:"XPlat Code Coverage"
310369

311370
## Run Performance Tests
312371

313-
### Running Performance test project directly:
372+
### Running Performance test project directly
314373

315374
Project location from Root: `src\Microsoft.Data.SqlClient\tests\PerformanceTests\Microsoft.Data.SqlClient.PerformanceTests.csproj`
316375
Configure `runnerconfig.json` file with connection string and preferred settings to run Benchmark Jobs.
317376

318-
```
377+
```bash
319378
cd src\Microsoft.Data.SqlClient\tests\PerformanceTests
320379
dotnet run -c Release -f netcoreapp3.1|net5.0
321380
```
381+
322382
_Only "**Release** Configuration" applies to Performance Tests_

0 commit comments

Comments
 (0)