Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8281063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:54:12+00:00 2026-06-08T09:54:12+00:00

In MsTest if I need some file from another project for my test, I

  • 0

In MsTest if I need some file from another project for my test, I can specify DeploymentItem attribute. Is there anything similar in NUnit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:54:14+00:00Added an answer on June 8, 2026 at 9:54 am

    You should check out another thread that contrasts the capabilities of NUnit and MSTest.

    The accepted answer here is misleading. NUnit does not offer the [DeploymentItem(“”)] attribute at all which is what @Idsa wanted an equivalent solution for in NUnit.

    My guess is that this kind of attribute would violate the scope of NUnit as a “unit” testing framework as requiring an item to be copied to the output before running a test implies it has a dependency on this resource being available.

    I’m using a custom attribute to copy over a localdb instance for running “unit” tests against some sizeable test data that I’d rather not generate with code everytime.

    Now using the attribute [DeploymentItem(“some/project/file”)] will copy this resource from file system into the bin again effectively refreshing my source data per test method:

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Struct, 
        AllowMultiple = false, 
        Inherited = false)]
    public class DeploymentItem : System.Attribute {
        private readonly string _itemPath;
        private readonly string _filePath;
        private readonly string _binFolderPath;
        private readonly string _itemPathInBin;
        private readonly DirectoryInfo _environmentDir;
        private readonly Uri _itemPathUri;
        private readonly Uri _itemPathInBinUri;
    
        public DeploymentItem(string fileProjectRelativePath) {
            _filePath = fileProjectRelativePath.Replace("/", @"\");
    
            _environmentDir = new DirectoryInfo(Environment.CurrentDirectory);
            _itemPathUri = new Uri(Path.Combine(_environmentDir.Parent.Parent.FullName
                , _filePath));
    
            _itemPath = _itemPathUri.LocalPath;
            _binFolderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    
            _itemPathInBinUri = new Uri(Path.Combine(_binFolderPath, _filePath));
            _itemPathInBin = _itemPathInBinUri.LocalPath;
    
            if (File.Exists(_itemPathInBin)) {
                File.Delete(_itemPathInBin);
            }
    
            if (File.Exists(_itemPath)) {
                File.Copy(_itemPath, _itemPathInBin);
            }
        }
    }
    

    Then we can use like so:

    [Test]
    [DeploymentItem("Data/localdb.mdf")]
    public void Test_ReturnsTrue() 
    {
        Assert.IsTrue(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my MSTest UnitTest project, before running any tests, I need to execute some
I am working on a project utilizing MSTest and I need similar constraints for
I need to run mstest from the command line - where in the world
I have a VS2010 unit test project set to using SpecFlow 1.8.1 and mstest.
Possible Duplicate: Where is mstest.exe located? I can run it from the Visual Studio
Is there a way to run only failed tests from a previous test run
I need to use some WPF components in an NUnit unit test. I run
I'm trying to get some database related integration tests running on a MSTest test
I need to use the ReSharper Unit Test Runner to run my MSTest Unit
I need to write a test which verifies that my code can handle an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.