File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ # File based C# application
2+
3+ Starting with dotnet 10 (preview 4), you can use the new file-based C# application feature to run tests in a more straightforward way.
4+
5+ ## Using File-Based C# Application with TUnit
6+
7+ To use TUnit with a file-based C# application, you can follow these steps:
8+
9+ 1 . ** Create a new C# file** : Create a new file with a ` .cs ` extension, for example, ` Program.cs ` .
10+ 2 . ** Add TUnit to your project** : You can add TUnit as a package reference in your file. At the top of your ` Program.cs ` , add the following line:
11+
12+ ``` csharp
13+ #:package TUnit@0.*
14+ ```
15+
16+ Alternatively , you can specify a specific version :
17+
18+ ```csharp
19+ #:package TUnit@0.25.0
20+ ```
21+
22+ 3 . ** Write your tests ** : You can write your tests in the same way you would in a regular C # project . For example :
23+
24+ ```csharp
25+ #:package TUnit@0.*
26+
27+ using TUnit ;
28+ public class Tests
29+ {
30+ [Test ]
31+ public void Basic ()
32+ {
33+ Console .WriteLine (" This is a basic test" );
34+ }
35+
36+ [Test ]
37+ [Arguments (1 , 2 , 3 )]
38+ [Arguments (2 , 3 , 5 )]
39+ public async Task DataDrivenArguments (int a , int b , int c )
40+ {
41+ Console .WriteLine (" This one can accept arguments from an attribute" );
42+ var result = a + b ;
43+ await Assert .That (result ).IsEqualTo (c );
44+ }
45+
46+ }
47+
48+ ```
49+
50+ 4 ** Run your tests ** : You can run your tests by executing the script in F # Interactive . The results will be printed to the console .
51+ To run the script , you can use the following command
52+
53+ ```powershell
54+ dotnet run Program .cs
55+ ```
56+
57+ If you need to convert the file based application to a regular C # project , you can run the following command :
58+
59+ ```powershell
60+ dotnet project convert Program .cs
61+ ```
Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ const sidebars: SidebarsConfig = {
129129 'examples/instrumenting-global-test-ids' ,
130130 'examples/tunit-ci-pipeline' ,
131131 'examples/fsharp-interactive' ,
132+ 'examples/filebased-csharp'
132133 ] ,
133134 } ,
134135 {
You can’t perform that action at this time.
0 commit comments