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 6699909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:07+00:00 2026-05-26T06:45:07+00:00

Here is my c# unit test design issue: I have one test that I

  • 0

Here is my c# unit test design issue:

I have one test that I want to run on some code that modifies a file. My test will run the code that modifies the file, then check the result. Pretty straight forward so far…

The issue is, I have about 10 files (soon to be a lot more) that I want to run the same unit test against. I dont want to write a new unit test for each file, when the test itself is really the same.

I could write a single test that queries the files in the folder and then runs the test logic on each file, but using this method would only report one pass/fail result for the entire set of files.

Id like to create some sort of dynamic system where every file that I place in a particular folder gets ran though this same unit test. So if 25 files are in the folder, the test gets ran 25 times, and the unit test reults report that 25 tests were ran, and includes seperate pass/fails for each.

Any ideas how or if this can be done in a c# unit test? Or with a nunit test?

Thanks! And I hope this is not a duplicate question. I looked around, but I could not find anything.

  • 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-05-26T06:45:08+00:00Added an answer on May 26, 2026 at 6:45 am

    Another option is to use T4 templates to dynamically generate tests for you based on the number of files in your directory. Add this “.tt” file to your unit test project.

    Now whenever you do a build which should happen just before you press the “Run all tests in solution” button in visual studio, it should generate unit tests for all the files in the directory with the file name in the unit test. Then your test run should have a nice list of all the files it tested and their statuses.

    <#@ template debug="false" hostspecific="true" language="C#v3.5" #>
    <#@ assembly name="System.Core.dll" #>
    <#@ assembly name="System.Data.dll" #>
    <#@ import namespace="System.IO" #>
    <#@ import namespace="System.Collections.Generic" #>
    <#@ import namespace="System.Linq" #>
    <#@ output extension=".cs" #>
    <#
                string inputDirectory = @"d:\temp";
                var files = System.IO.Directory.GetFiles(inputDirectory);
    #>
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace TestProject1
    {
        [TestClass]
        public class UnitTest1
        {
            <# foreach (string filePath in files) { #>
            [TestMethod]
            public void TestingFile_<#=System.IO.Path.GetFileNameWithoutExtension(filePath).Replace(' ','_').Replace('-','_')#>()
            {
            File currentFile = System.IO.File.Open(@"<#= filePath #>", FileMode.Open);
            // TODO: Put your standard test code here which will use the file you opened above
            }
            <# } #>
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple unit test case (extensive question here ) on a configuration
Here is the issue I am having: I have a large query that needs
I have the below class I want to unit test: public class MyClass {
I'm having trouble writing a unit test for one of my controller actions. Here's
I'm trying to use embedded ActiveMQ broker for unit testing, as explained here: http://activemq.apache.org/how-to-unit-test-jms-code.html
I've got a unit test I'm writing which seems to have some kind of
I have a unit-test that tests a variety of cases, like this: public void
Here's the scenario: I have a method that reads in a file via a
I work with unit test in Rails.., Here is my code located in test\unit\sample_test.rb
Here's my scenario - I have an SSIS job that depends on another prior

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.