question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeploymentItem doesn't work for pure test class without test methods

See original GitHub issue

Description

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() { }
    }

AB#1681020

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
vagisha-nidhicommented, Sep 9, 2019

@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.

<MSTestV2>
    <DeployTestSourceDependencies>false</DeployTestSourceDependencies>
</MSTestV2>

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.

0reactions
Evangelinkcommented, Nov 18, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - DeploymentItem not deploying files
I have to open a file which I'm deploying using DeploymentItem attribute . But it is not deploying file to the Test deployment...
Read more >
Deploy Supporting Files as Part of Your VSTS Unit Tests
[DeploymentItem] has a major drawback: It's allowed only on methods—not classes. This might be fine if your configuration file is required on ...
Read more >
Attribute Extensions - Progress Test Studio
Attribute Extensions are test fixture attributes that can be used to decorate unit test methods or classes to describe FindParam objects and dialog...
Read more >
DeploymentItem for specific testmethod gets ...
1 the following issues seem to occur: When running tests, similar to the below two tests, by right clicking in the test-class and...
Read more >
DeploymentItemAttribute Class
Use DeploymentItemAttribute on test methods or test classes to specify the files and folders that should be copied from the build output ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found