@@ -13,11 +13,21 @@ To use TUnit with a file-based C# application, you can follow these steps:
1313 #:package TUnit @0.*
1414 ```
1515
16- Alternatively , you can specify a specific version :
16+ - Alternatively , you can specify a specific version :
1717
18- ```csharp
19- #:package TUnit @0.25.0
20- ```
18+ ```csharp
19+ #:package TUnit @0.25.0
20+ ```
21+
22+ - You can also use msbuild props files to include TUnit . By creating a `Directory .build .props ` file in the same directory as the csharp file .
23+
24+ ```xml
25+ < Project >
26+ < ItemGroup >
27+ < PackageReference Include = " TUnit" Version = " *" / >
28+ < / ItemGroup >
29+ < / Project >
30+ ```
2131
22323 . ** Write your tests ** : You can write your tests in the same way you would in a regular C # project . For example :
2333
@@ -47,7 +57,7 @@ To use TUnit with a file-based C# application, you can follow these steps:
4757
4858 ```
4959
50- 4 . ** Run your tests ** : You can run your tests by executing the script using `dotnet run `. The results will be printed to the console .
60+ 4 . ** Run your tests ** : You can run your tests by executing the script using `dotnet run `. The results will be printed to the console .
5161 To run the script , you can use the following command
5262
5363 ```powershell
@@ -59,3 +69,49 @@ If you need to convert the file based application to a regular C# project, you c
5969 ```powershell
6070 dotnet project convert Program .cs
6171 ```
72+
73+ ## Using msbuild props with File -Based C # Application
74+
75+ Single file csharp applications can also be used with msbuild props files . You can create a `*.props ` file and the dotnet sdk will automatically include it when running the file -based application .
76+
77+ 1. Create a file named `Directory .build .props ` with the following content :
78+
79+ ```xml
80+ <Project >
81+ <ItemGroup >
82+ <PackageReference Include = "TUnit " Version = "*" />
83+ </ItemGroup >
84+ </Project >
85+ ```
86+
87+ 2. Create a csharp file with the following content :
88+
89+ ```csharp
90+ using TUnit ;
91+ public class Tests
92+ {
93+ [Test ]
94+ public void Basic ()
95+ {
96+ Console .WriteLine (" This is a basic test" );
97+ }
98+
99+ [Test ]
100+ [Arguments (1 , 2 , 3 )]
101+ [Arguments (2 , 3 , 5 )]
102+ public async Task DataDrivenArguments (int a , int b , int c )
103+ {
104+ Console .WriteLine (" This one can accept arguments from an attribute" );
105+ var result = a + b ;
106+ await Assert .That (result ).IsEqualTo (c );
107+ }
108+ }
109+ ```
110+
111+ 3 . Run the script using the following command :
112+
113+ ```powershell
114+ dotnet run file .cs
115+ ```
116+
117+ This will automatically include the `Directory .build .props ` file as long as it is in the same directory as the csharp file , and you will be able to run your tests with TUnit .
0 commit comments