├── .vscode
├── settings.json
├── launch.json
└── tasks.json
├── screenshot1.png
├── test.cmd
├── The.Thing
├── The.Thing.csproj
└── Class1.cs
├── The.Tests
├── UnitTest1.cs
└── The.Tests.csproj
├── readme.md
├── testtester.sln
└── .gitignore
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "dotnet-test-explorer.testProjectPath": "./The.Tests"
3 | }
--------------------------------------------------------------------------------
/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shanselman/dotnetcoreunittestingwithcoverageinvscode/master/screenshot1.png
--------------------------------------------------------------------------------
/test.cmd:
--------------------------------------------------------------------------------
1 | dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info ./The.Tests/The.Tests.csproj
--------------------------------------------------------------------------------
/The.Thing/The.Thing.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/The.Thing/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace The.Thing
4 | {
5 | public class Calculator
6 | {
7 | public long Add(int a, int b)
8 | {
9 | int result = a+b;
10 | if (result >= 10)
11 | {
12 | return ++result;
13 | }
14 | return result;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/The.Tests/UnitTest1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using The.Thing;
3 | using Xunit;
4 |
5 | namespace The.Tests
6 | {
7 | public class UnitTest1
8 | {
9 | [Fact]
10 | public void Test2()
11 | {
12 | Calculator c = new Calculator();
13 | Assert.Equal(8, c.Add(5,3));
14 | }
15 |
16 | [Fact]
17 | public void Test3()
18 | {
19 | Calculator c = new Calculator();
20 | Assert.Equal(4, c.Add(2,2));
21 | }
22 |
23 | [Fact]
24 | public void Test1()
25 | {
26 | Calculator c = new Calculator();
27 | Assert.Equal(12,c.Add(5,6));
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/The.Tests/The.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/The.Tests/bin/Debug/netcoreapp2.1/The.Tests.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}/The.Tests",
16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17 | "console": "internalConsole",
18 | "stopAtEntry": false,
19 | "internalConsoleOptions": "openOnSessionStart"
20 | },
21 | {
22 | "name": ".NET Core Attach",
23 | "type": "coreclr",
24 | "request": "attach",
25 | "processId": "${command:pickProcess}"
26 | }
27 | ,]
28 | }
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | Using VS Code, [Coverlet](https://github.com/tonerdo/coverlet/), xUnit, plus these extensions
2 |
3 | - [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters)
4 | - Reads in the lcov.info file (name matters) and highlights lines with color
5 | - [.NET Core Test Explorer](https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet-test-explorer)
6 | - Discovers tests and gives you a nice explorer.
7 | - [Coverlet](https://github.com/tonerdo/coverlet/)
8 | - The start of .NET Core Code Coverage
9 |
10 | 
11 |
12 | Note the tasks.json, specifically this part. If you name the file lcov.info, the Coverage Gutters extension will pick up and color the line numbers.
13 |
14 | ```
15 | {
16 | "label": "test with coverage",
17 | "command": "dotnet",
18 | "type": "process",
19 | "args": [
20 | "test",
21 | "/p:CollectCoverage=true",
22 | "/p:CoverletOutputFormat=lcov",
23 | "/p:CoverletOutput=./lcov.info",
24 | "${workspaceFolder}/The.Tests/The.Tests.csproj"
25 | ],
26 | "problemMatcher": "$msCompile",
27 | "group": {
28 | "kind": "test",
29 | "isDefault": true
30 | }
31 | },
32 | ```
33 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/The.Tests/The.Tests.csproj"
11 | ],
12 | "problemMatcher": "$msCompile",
13 | "group": {
14 | "kind": "build",
15 | "isDefault": true
16 | }
17 | },
18 | {
19 | "label": "test",
20 | "command": "dotnet",
21 | "type": "process",
22 | "args": [
23 | "test",
24 | "${workspaceFolder}/The.Tests/The.Tests.csproj"
25 | ],
26 | "problemMatcher": "$msCompile",
27 | "group": {
28 | "kind": "test",
29 | "isDefault": true
30 | }
31 | },
32 | {
33 | "label": "test with coverage",
34 | "command": "dotnet",
35 | "type": "process",
36 | "args": [
37 | "test",
38 | "/p:CollectCoverage=true",
39 | "/p:CoverletOutputFormat=lcov",
40 | "/p:CoverletOutput=./lcov.info",
41 | "${workspaceFolder}/The.Tests/The.Tests.csproj"
42 | ],
43 | "problemMatcher": "$msCompile",
44 | "group": {
45 | "kind": "test",
46 | "isDefault": true
47 | }
48 | },
49 | ]
50 | }
--------------------------------------------------------------------------------
/testtester.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26124.0
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "The.Thing", "The.Thing\The.Thing.csproj", "{449AEE54-F315-4160-B445-3707DED1731E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Debug|x86 = Debug|x86
13 | Release|Any CPU = Release|Any CPU
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {449AEE54-F315-4160-B445-3707DED1731E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {449AEE54-F315-4160-B445-3707DED1731E}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {449AEE54-F315-4160-B445-3707DED1731E}.Debug|x64.ActiveCfg = Debug|Any CPU
24 | {449AEE54-F315-4160-B445-3707DED1731E}.Debug|x64.Build.0 = Debug|Any CPU
25 | {449AEE54-F315-4160-B445-3707DED1731E}.Debug|x86.ActiveCfg = Debug|Any CPU
26 | {449AEE54-F315-4160-B445-3707DED1731E}.Debug|x86.Build.0 = Debug|Any CPU
27 | {449AEE54-F315-4160-B445-3707DED1731E}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {449AEE54-F315-4160-B445-3707DED1731E}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {449AEE54-F315-4160-B445-3707DED1731E}.Release|x64.ActiveCfg = Release|Any CPU
30 | {449AEE54-F315-4160-B445-3707DED1731E}.Release|x64.Build.0 = Release|Any CPU
31 | {449AEE54-F315-4160-B445-3707DED1731E}.Release|x86.ActiveCfg = Release|Any CPU
32 | {449AEE54-F315-4160-B445-3707DED1731E}.Release|x86.Build.0 = Release|Any CPU
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | coverage.json
17 | lcov.info
18 | *.min.js
19 | *.min.css
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | bld/
27 | [Bb]in/
28 | [Oo]bj/
29 | [Ll]og/
30 |
31 | # Visual Studio 2015 cache/options directory
32 | .vs/
33 | # Uncomment if you have tasks that create the project's static files in wwwroot
34 | #wwwroot/
35 |
36 | # MSTest test Results
37 | [Tt]est[Rr]esult*/
38 | [Bb]uild[Ll]og.*
39 |
40 | # NUNIT
41 | *.VisualState.xml
42 | TestResult.xml
43 |
44 | # Build Results of an ATL Project
45 | [Dd]ebugPS/
46 | [Rr]eleasePS/
47 | dlldata.c
48 |
49 | # .NET Core
50 | project.lock.json
51 | project.fragment.lock.json
52 | artifacts/
53 | **/Properties/launchSettings.json
54 |
55 | *_i.c
56 | *_p.c
57 | *_i.h
58 | *.ilk
59 | *.meta
60 | *.obj
61 | *.pch
62 | *.pdb
63 | *.pgc
64 | *.pgd
65 | *.rsp
66 | *.sbr
67 | *.tlb
68 | *.tli
69 | *.tlh
70 | *.tmp
71 | *.tmp_proj
72 | *.log
73 | *.vspscc
74 | *.vssscc
75 | .builds
76 | *.pidb
77 | *.svclog
78 | *.scc
79 |
80 | # Chutzpah Test files
81 | _Chutzpah*
82 |
83 | # Visual C++ cache files
84 | ipch/
85 | *.aps
86 | *.ncb
87 | *.opendb
88 | *.opensdf
89 | *.sdf
90 | *.cachefile
91 | *.VC.db
92 | *.VC.VC.opendb
93 |
94 | # Visual Studio profiler
95 | *.psess
96 | *.vsp
97 | *.vspx
98 | *.sap
99 |
100 | # TFS 2012 Local Workspace
101 | $tf/
102 |
103 | # Guidance Automation Toolkit
104 | *.gpState
105 |
106 | # ReSharper is a .NET coding add-in
107 | _ReSharper*/
108 | *.[Rr]e[Ss]harper
109 | *.DotSettings.user
110 |
111 | # JustCode is a .NET coding add-in
112 | .JustCode
113 |
114 | # TeamCity is a build add-in
115 | _TeamCity*
116 |
117 | # DotCover is a Code Coverage Tool
118 | *.dotCover
119 |
120 | # Visual Studio code coverage results
121 | *.coverage
122 | *.coveragexml
123 |
124 | # NCrunch
125 | _NCrunch_*
126 | .*crunch*.local.xml
127 | nCrunchTemp_*
128 |
129 | # MightyMoose
130 | *.mm.*
131 | AutoTest.Net/
132 |
133 | # Web workbench (sass)
134 | .sass-cache/
135 |
136 | # Installshield output folder
137 | [Ee]xpress/
138 |
139 | # DocProject is a documentation generator add-in
140 | DocProject/buildhelp/
141 | DocProject/Help/*.HxT
142 | DocProject/Help/*.HxC
143 | DocProject/Help/*.hhc
144 | DocProject/Help/*.hhk
145 | DocProject/Help/*.hhp
146 | DocProject/Help/Html2
147 | DocProject/Help/html
148 |
149 | # Click-Once directory
150 | publish/
151 |
152 | # Publish Web Output
153 | *.[Pp]ublish.xml
154 | *.azurePubxml
155 | # TODO: Comment the next line if you want to checkin your web deploy settings
156 | # but database connection strings (with potential passwords) will be unencrypted
157 | *.pubxml
158 | *.publishproj
159 |
160 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
161 | # checkin your Azure Web App publish settings, but sensitive information contained
162 | # in these scripts will be unencrypted
163 | PublishScripts/
164 |
165 | # NuGet Packages
166 | *.nupkg
167 | # The packages folder can be ignored because of Package Restore
168 | **/packages/*
169 | # except build/, which is used as an MSBuild target.
170 | !**/packages/build/
171 | # Uncomment if necessary however generally it will be regenerated when needed
172 | #!**/packages/repositories.config
173 | # NuGet v3's project.json files produces more ignorable files
174 | *.nuget.props
175 | *.nuget.targets
176 |
177 | # Microsoft Azure Build Output
178 | csx/
179 | *.build.csdef
180 |
181 | # Microsoft Azure Emulator
182 | ecf/
183 | rcf/
184 |
185 | # Windows Store app package directories and files
186 | AppPackages/
187 | BundleArtifacts/
188 | Package.StoreAssociation.xml
189 | _pkginfo.txt
190 |
191 | # Visual Studio cache files
192 | # files ending in .cache can be ignored
193 | *.[Cc]ache
194 | # but keep track of directories ending in .cache
195 | !*.[Cc]ache/
196 |
197 | # Others
198 | ClientBin/
199 | ~$*
200 | *~
201 | *.dbmdl
202 | *.dbproj.schemaview
203 | *.jfm
204 | *.pfx
205 | *.publishsettings
206 | orleans.codegen.cs
207 |
208 | # Since there are multiple workflows, uncomment next line to ignore bower_components
209 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
210 | #bower_components/
211 |
212 | # RIA/Silverlight projects
213 | Generated_Code/
214 |
215 | # Backup & report files from converting an old project file
216 | # to a newer Visual Studio version. Backup files are not needed,
217 | # because we have git ;-)
218 | _UpgradeReport_Files/
219 | Backup*/
220 | UpgradeLog*.XML
221 | UpgradeLog*.htm
222 |
223 | # SQL Server files
224 | *.mdf
225 | *.ldf
226 | *.ndf
227 |
228 | # Business Intelligence projects
229 | *.rdl.data
230 | *.bim.layout
231 | *.bim_*.settings
232 |
233 | # Microsoft Fakes
234 | FakesAssemblies/
235 |
236 | # GhostDoc plugin setting file
237 | *.GhostDoc.xml
238 |
239 | # Node.js Tools for Visual Studio
240 | .ntvs_analysis.dat
241 | node_modules/
242 |
243 | # Typescript v1 declaration files
244 | typings/
245 |
246 | # Visual Studio 6 build log
247 | *.plg
248 |
249 | # Visual Studio 6 workspace options file
250 | *.opt
251 |
252 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
253 | *.vbw
254 |
255 | # Visual Studio LightSwitch build output
256 | **/*.HTMLClient/GeneratedArtifacts
257 | **/*.DesktopClient/GeneratedArtifacts
258 | **/*.DesktopClient/ModelManifest.xml
259 | **/*.Server/GeneratedArtifacts
260 | **/*.Server/ModelManifest.xml
261 | _Pvt_Extensions
262 |
263 | # Paket dependency manager
264 | .paket/paket.exe
265 | paket-files/
266 |
267 | # FAKE - F# Make
268 | .fake/
269 |
270 | # JetBrains Rider
271 | .idea/
272 | *.sln.iml
273 |
274 | # CodeRush
275 | .cr/
276 |
277 | # Python Tools for Visual Studio (PTVS)
278 | __pycache__/
279 | *.pyc
280 |
281 | # Cake - Uncomment if you are using it
282 | # tools/**
283 | # !tools/packages.config
284 |
285 | # Telerik's JustMock configuration file
286 | *.jmconfig
287 |
288 | # BizTalk build output
289 | *.btp.cs
290 | *.btm.cs
291 | *.odx.cs
292 | *.xsd.cs
293 | wwwroot/css/site.min.css
294 | wwwroot/js/site.min.js
295 |
--------------------------------------------------------------------------------