DeploymentItem doesn't work for pure test class without test methods
See original GitHub issueDescription
According to the documentation the DeploymentItem can
be specified on test class or test method (src)
Anyways, when applying the DeploymentItem to a TestClass which only contains a (valid) AssemblyInitialize- or AssemblyCleanup-Method, the specified resource won’t be deployed.
This seems due to the fact that currently the deployment item is only evaluated for TestCase-items (see src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs line 52).
Either the documentation should be updated or the deployment item should be evaluated for any class regarding the existence of a test method. Another solution could be enabling the DeploymentItem attribute to target assemblies.
Steps to reproduce
[DeploymentItem("Resource.bin")]
[TestClass] //Note the TestClass-attribute
public class Class1
{
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
Assert.IsTrue(File.Exists("Resource.bin")); //Fails
}
}
Expected behavior
Assert.IsTrue succeeds
Actual behavior
Assert.IsTrue fails
Workaround
As a workaround an empty bodied test method can be added. Then it works as expected:
[DeploymentItem("Resource.bin")]
[TestClass] //Note the TestClass-attribute
public class Class1
{
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
Assert.IsTrue(File.Exists("Resource.bin")); //Fails
}
[TestMethod]
public void ForceDeployment() { }
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@N-Olbert There is one more thing you can try out. You can keep your files (that you are using to deploy) in your output directory(bin/debug) and use this setting node your runsettings file.
What this basically does is that it will copy every thing from your output directory into the deployment directory (won’t figure out dependencies on its own) and run tests from there. I will log a doc bug to address this issue.
I confirm that I can reproduce the issue raised here. Given the few upvotes and the fact this is “broken” since a long time, I will move forward by updating the documentation to mention this is not a supported behavior.