PHPUnit doesn't load some of the tests - unit-testing

I have a tests folder in one of my modules, with 3 subfolders:
Model
Helper
Integration
running
phpunit --group My_Module
executes only the tests in Model and Helper directories, with the Integration folder left untouched. Test files reside directly in the folder in all of the cases, so I'm not sure what's causing the problem.
Here's my phpunit.xml:
<?xml version="1.0"?>
<!-- initial phpunit configuration file, that you can modify for your project needs -->
<phpunit cacheTokens="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
strict="false"
verbose="false"
bootstrap="app/code/community/EcomDev/PHPUnit/bootstrap.php">
<listeners>
<listener file="app/code/community/EcomDev/PHPUnit/Test/Listener.php" class="EcomDev_PHPUnit_Test_Listener" />
</listeners>
<testsuites>
<testsuite name="MyApp">
<directory suffix=".php">app/code/local/*/*/Test/*/</directory>
</testsuite>
<testsuite name="Magento Test Suite">
<file>app/code/community/EcomDev/PHPUnit/Test/Suite.php</file>
</testsuite>
</testsuites>
<filter>
<blacklist>
<!-- Exclude Magento Core files from code coverage -->
<directory suffix=".php">app/code/core</directory>
<!-- Exclude EcomDev_PHPUnit classes from code coverage -->
<directory suffix=".php">app/code/community/EcomDev/PHPUnit</directory>
<directory suffix=".php">lib/EcomDev/Utils</directory>
<directory suffix=".php">lib/EcomDev/PHPUnit</directory>
<directory suffix=".php">lib/Spyc</directory>
<directory suffix=".php">lib/vfsStream</directory>
<!-- Exclude Mage.php file from code coverage -->
<file>app/Mage.php</file>
<!-- Exclude template files -->
<directory suffix=".phtml">app/design</directory>
<!-- Exclude Varien & Zend libraries -->
<directory suffix=".php">lib/Varien</directory>
<directory suffix=".php">lib/Zend</directory>
</blacklist>
</filter>
<logging>
<!-- Uncomment this line if you want to have coverage report generated every test run
<log type="coverage-html" target="var/phpunit/coverage" charset="UTF-8"
yui="true" highlight="false"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="var/phpunit/coverage.xml"/>
-->
<log type="junit" target="../build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
The version of PHPunit I'm running on ubuntu VM is 3.7.28. How can I get all of the tests to run? Help would be much appreciated.

Try to call
phpunit --list-groups
This show you list of available test groups. Do you see My_Module in list?
1) Yes - issue in tests folders/structure.
2) No - issue in xml configuration.

Related

How to exclude method in coverlet coverage report?

How can I exclude a method from code coverage reporting using coverlet and reportgenerator. Excluding entire namespaces in .runsettings works as expected but using [ExcludeFromCodeCoverage] attribute excludes the entire file instead of only the targeted method. See Comments below for what I've tried in .runsettings.
relevant .runsettings lines:
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector>
<Configuration>
<Format>lcov</Format>
<Include>[*]*</Include>
<Exclude>
<!-- excluded namespaces -->
</Exclude>
<!-- excludes entire file from coverage -->
<ExcludeByAttribute>Obsolete, GeneratedCodeAttribute, CompilerGeneratedAttribute,ExcludeFromCodeCoverage</ExcludeByAttribute>
<!-- included & reported as uncovered -->
<ExcludeByAttribute> ExcludeFromCodeCoverageAttribute </ExcludeByAttribute>
<SingleHit>true</SingleHit>
<UseSourceLink>true</UseSourceLink>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- included and reported as uncovered -->
<CodeCoverage>
<Attributes>
<Exclude>
<Attribute> ^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
UPDATE: It seems to have been a recently resolved issue with coverlet. Updating resolved the issue. https://github.com/coverlet-coverage/coverlet/issues/809
Just apply [ExcludeFromCodeCoverage] on the method instead of the class.

How to prevent Wix from overwriting directories on install

I have a Windows app which has 2 versions, kind of, but a different name for each version. I use the same .wxs to build because I have no reasons to create a second wix project. I do not want to argue wether it is a good idea in here.
The thing is: each version must be installed in
path \ mainDir \ versionDir
Where path \ mainDir is the same for each version.
My problem is that mainDir is being entirely overwritten on install by each version.
Let's say I install version1, I'll have
path \ mainDir \ version1Dir
And then if I install version2, instead of having
path \ mainDir \ version1Dir
path \ mainDir \ version2Dir
I'll have
path \ mainDir \ version2Dir
I've been trying to get this around using Wix - how to prevent overwrite entire directory?, but it only applies to files since Conditions cannot be assigned to directories (or maybe I have haven't found how to do so, I don't know).
My goal is to have each versions able to install in its own directory, creating mainDir if it doesn't exist, but only removing it if it's empty.
Here's the code, any leads would be very much appreciated.
<!-- This is in Product, I'm just pasting it here -->
<Property Id="ALREADYINSTALLED">
<RegistrySearch Id="InstallPath" Key="Software\$(var.MainDir)" Name="MainFolder" Root="HKCU" Type="directory" />
</Property>
<Property Id="SECONDALREADYINSTALLED">
<RegistrySearch Id="SecondInstallPath" Key="Software\$(var.MainDir)\$(var.SecondDir)" Name="SecondFolder" Root="HKCU" Type="directory" />
</Property>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="WINDOWSVOLUME">
<Directory Id="INSTALLFOLDER" Name=".">
<Directory Id="MAINFOLDER" Name="$(var.MainDir)">
<!-- Allows the removal of this directory on uninstall -->
<Component Id="mainFolderRemoval">
<RegistryValue Root="HKCU" Key="Software\$(var.MainDir)" Name="MainFolder" Type="string" KeyPath="yes" />
<RemoveFolder Id="removal" On="uninstall" Property="ALREADYINSTALLED"/>
</Component>
<Directory Id="SECONDFOLDER" Name="$(var.SecondDir)">
<Component Id="secondFolderRemoval">
<RegistryValue Root="HKCU" Key="Software\$(var.MainDir)\$(var.SecondDir)" Name="SecondFolder" Type="string" KeyPath="yes" />
<util:RemoveFolderEx On="uninstall" Property="SECONDALREADYINSTALLED"/>
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
<SetDirectory Id="WINDOWSVOLUME" Value="[WindowsVolume]" />
<!-- Overwrites the main folder if already installed -->
<SetDirectory Id="MAINFOLDER" Value="[ALREADYINSTALLED]"> <![CDATA[ALREADYINSTALLED]]> </SetDirectory>
</Fragment>
So I ended up finding why it wouldn't work.
You have to make sure that your product upgrade code is different for each version, which was quite obvious actually.
One could argue that I should delete this post, but I believe it could happen to anyone and this is too much of a stupid issue to let people loose time with this. I'll leave this question as an example, hopefully it might be useful to somebody in the future.

WiX Heat.exe generates different output after VS2008 -> VS2015 upgrade

We execute the following command line with heat (3.0.5210.0):
heat.exe -srd -suid file OurLib.dll -out bin_OurLib.tmp
OurLib.dll is a VC++ 2008 dll file, it's a COM component.
Output (bin_OurLib.tmp)
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="OurLib.dll" Guid="PUT-GUID-HERE">
<File Id="OurLib.dll" KeyPath="yes" Source="SourceDir\OurLib.dll">
<Class Id="{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}" Context="InprocServer32" Description="OurProduct.OurLib">
<ProgId Id="OurProduct.OurLib" Description="OurProduct.OurLib" />
</Class>
</File>
</Component>
</DirectoryRef>
</Fragment>
</Wix>
This works fine.
Now we updated the VS to 2015, and compiled OurLib with it.
Running the same heat command now results in different output:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="OurLib.dll" Guid="PUT-GUID-HERE">
<Class Id="{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}" Context="InprocServer32" Description="OurProduct.OurLib">
<ProgId Id="OurProduct.OurLib" Description="OurProduct.OurLib" />
</Class>
<File Id="OurLib.dll" KeyPath="yes" Source="SourceDir\OurLib.dll" />
<RegistryValue Root="HKCR" Key="CLSID\{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}\InProcServer32" Value=""[#OurLib.dll]"" Type="string" Action="write" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
And when wix is linking, it gives error:
error LGHT0130 : The primary key 'reg51A1FC16367511AF81E9B18CA009A1C6' is duplicated in table 'Registry'. Please remove one of the entries or rename a part of the primary key to avoid the collision.
Checking the wixobj file, reg51A1FC16367511AF81E9B18CA009A1C6 is related to line
<Class Id="{B1AB297C-1BC6-65E1-A7C1-A1833DFAED6A}...." and <RegistryValue Root="HKCR" Key="CLSID\{B1AB.... - obviously.
Anwyay, this is obviously due to the generated wix output files are different.
Why is that if compiling a dll with a newer C++ compiler will cause WIX HEAT to generate different output, while running the same options, etc.
And how can I have back the same "old" output, which we need.
Tried with -scom and -sreg, none of them gave back the "old" output.
Well primary key duplicated means you've got that same RegistryValue in two different places in your wix source code somehow.
Or maybe the newer DLL is self-registering differently? It's putting the InProcServer32 value in quotes. I don't think that's normal.
Or have you checked that your 2008 and 2015 DLL source and project files are identical? The VS project upgrade process changes things...

Visual Studio .runsettings excluding too many assemblies

I am using a .runsettings file to manage the assemblies which generate code coverage results.
With the following section in my .runsettings file I get all the assemblies including my test projects some unwanted TFSBuildExtensions assemblies:
<!-- Match assembly file paths: -->
<ModulePaths>
<Include />
<Exclude />
</ModulePaths>
So I modified it to exclude my test projects which are all named MyCompany.MyProject1.Tests.dll
<!-- Match assembly file paths: -->
<ModulePaths>
<Include />
<Exclude>
<ModulePath>.*Tests.*</ModulePath>
</Exclude>
</ModulePaths>
However now all my assemblies are excluded and I'm left only with the TFSBuildExtensions assemblies.
What should I be specifying in the exclude section to exclude the following assemblies?
MyCompany.MyProject1.Tests.dll
...
MyCompany.AnyProjectName.Tests.dll
TFSBuildExtensions.XXX.dll
OK so I found what the issue was here: https://stackoverflow.com/a/15961727/283787
The Regex is looking for a path, not just a module name, you need the .* in front of the module to ignore it – that is, you want to ignore it at any given file path.
So when I changed it to following it worked fine:
<ModulePaths>
<Exclude>
<ModulePath>.*tests\.dll$</ModulePath>
<ModulePath>.*tfsbuildextensions\..*\.dll$</ModulePath>
</Exclude>
</ModulePaths>
This should do what you want:
<!-- Match assembly file paths: -->
<ModulePaths>
<Include />
<Exclude>
<ModulePath>^.*Tests\.dll$</ModulePath>
<ModulePath>^tfsbuildextensions\..*\.dll$</ModulePath>
</Exclude>
</ModulePaths>

WiX Make a Sub-Dir a Component Group when running heat

Hello all my fellow WiX'ers,
I was wondering if it possible, and if so where I can go to learn how to do it, to run heat on a directory and have each directory inside that one be it's own Component Group.
Example:
Root Directory
Sub Dir 1
Sub Sub Dir 1
Sub Sub Dir 2
Sub Sub Dir 3
Sub Dir 2
Sub Sub Dir 1
Sub Sub Dir 2
Sub Sub Dir 3
Sub Dir 3
Sub Sub Dir 1
Sub Sub Dir 2
Sub Sub Dir 3
Then run a heat command in the Build Event of the VS2010 project (example below):
heat dir "Root Directory" -gg -sfrag -srd -dr INSTALLFOLDER -out MyWXS.wxs
and then have that WXS file structured like so:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirecotryRef Id="INSTALLFOLDER">
<Directory Id="dir84156489" Name="Sub Dir 1"> ... </Directory>
<Directory Id="dir84156489" Name="Sub Dir 2"> ... </Directory>
<Directory Id="dir84156489" Name="Sub Dir 3"> ... </Directory>
</DirectoryRed>
</Fragment>
<Fragment>
<ComponentGroup Id="Sub Dir 1"> ... </ComponentGroup>
<ComponentGroup Id="Sub Dir 2"> ... </ComponentGroup>
<ComponentGroup Id="Sub Dir 3"> ... </ComponentGroup>
</Fragment>
</wix>
If there is any confusion in my question or if anyone has any additional questions for me please let me know. Thank you and I look forward to hearing from you.
EDIT
Using the following xslt file I am getting the WXS structure that follows after:
**XLST File**
<?xml version="1.0" encoding="utf-8"?>
**WXS File Result**
<Wix>
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Directory Id="dir846546" Name="SubDir1"> ... </Directory>
<Directory Id="dir846546" Name="SubDir2"> ... </Directory>
<Directory Id="dir846546" Name="SubDir3"> ... </Directory>
</DirectoryRef>
</Fragment>
<wix:Fragment xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<wix:ComponentGroup Id="SubDur1"> ... </wix:ComponentGroup>
</wix:Fragment>
<wix:Fragment xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<wix:ComponentGroup Id="SubDur2"> ... </wix:ComponentGroup>
</wix:Fragment>
<wix:Fragment xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<wix:ComponentGroup Id="SubDur3"> ... </wix:ComponentGroup>
</wix:Fragment>
</Wix>
No matter what I do I cannot get the Directories to be created as component groups...
Heat can do an XSL transform before emitting its output. Just add the -t transform.xsl argument.
All that's needed is to append a few component groups to the output. Generate a component group by matching on a first-level directory and then referencing all of the descendent components.
See the XSL for my answer to a similar question.