0

I wrote a function for dbatools called New-DbaSqlConnectionStringBuilder. I wrote unit tests for it. I know these unit tests cover most of the function. I am getting 0% code coverage report with the following command.

Invoke-Pester .\tests\New-DbaSqlConnectionStringBuilder.Tests.ps1 -CodeCoverage .\functions\New-DbaSqlConnectionStringBuilder.ps1

Abridged output below:

**********************

Running C:\Users\zippy\Documents\dbatools\tests\New-

. . .
Unit tests happen
. . .


Passed: 16 Failed: 0 Skipped: 0 Pending: 0 Inconclusive: 0


Code coverage report:
Covered 0.00% of 21 analyzed commands in 1 file.

To get this version of the code:

git clone https://github.com/zippy1981/dbatools.git
cd dbatools
git checkout testing/PesterCodeCoverage
Import-Module .\dbatools.psd1

What am I doing wrong?

alroc
  • 27,574
  • 6
  • 51
  • 97
Justin Dearing
  • 14,270
  • 22
  • 88
  • 161
  • Can you show how you include the file with functions you are testing. It seems that the tests are running on the module and not on the actual file with src code. Do not load the module for testing, only the file you want for code coverage. – Peter Oct 03 '17 at 11:32
  • @Peter Yes that was it sorry I didn't update. I loaded the module. When I went and .\ the particula script then code coverage worked. Is there anyway around that? This is for dbatools. We have a file per cmdlet and I'd like to generate a code coverate report for everything. – Justin Dearing Oct 04 '17 at 17:41

1 Answers1

1

Just psychic debugging:

Your module is installed and your test are running against the module instead of the: ' .\functions\New-DbaSqlConnectionStringBuilder.ps1' file.

Peter
  • 27,590
  • 8
  • 64
  • 84