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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:43:01+00:00 2026-06-06T14:43:01+00:00

Just some example code here, but I have lists of strings that I want

  • 0

Just some example code here, but I have lists of strings that I want to test my functions against. The part that I don’t like is that NUnit stops in each test when the first Assert fails. I’d like to test each value and report each failure, rather than just the first one. I don’t want to have to write a new [Test] function for each string though.

Is there a way to do this?

using NUnit.Framework;
using System.Collections.Generic;

namespace Examples
{
    [TestFixture]
    public class ExampleTests
    {
        private List<string> validStrings = new List<string> { "Valid1", "valid2", "valid3", "Valid4" };
        private List<string> invalidStrings = new List<string> { "Invalid1", "invalid2", "invalid3", "" };

        [Test]
        public void TestValidStrings()
        {
            foreach (var item in validStrings)
            {
                Assert.IsTrue(item.Contains("valid"), item);
            }
        }

        [Test]
        public void TestInvalidStrings()
        {
            foreach (var item in invalidStrings)
            {
                Assert.IsFalse(item.Contains("invalid"), item);
            }
        }
    }
}
  • 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-06T14:43:01+00:00Added an answer on June 6, 2026 at 2:43 pm

    Use the [TestCaseSource] attribute to specify values to pass into your (now parameterized) test method.

    We use this a lot in Noda Time to test a lot of cases with different cultures and strings.

    Here’s your example, converted to use it:

    using NUnit.Framework;
    using System.Collections.Generic;
    
    // Namespace removed for brevity    
    [TestFixture]
    public class ExampleTests
    {
        private List<string> validStrings = new List<string> 
            { "Valid1", "valid2", "valid3", "Valid4" };
        private List<string> invalidStrings = new List<string> 
            { "Invalid1", "invalid2", "invalid3", "" };
    
        [Test]
        [TestCaseSource("validStrings")]
        public void TestValidStrings(string item)
        {
            Assert.IsTrue(item.Contains("valid"), item);
        }
    
        [Test]
        [TestCaseSource("invalidStrings")]
        public void TestInvalidStrings(string item)
        {
            Assert.IsFalse(item.Contains("invalid"), item);
        }
    }
    

    Note that another option is to use [TestCase] which means you don’t need separate variables for your test data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just learning Haskell and I am trying to write some code that simply
I have the following section of code that acts on values in <Test></Test> nodes
I have some code where I'm returning an array of objects. Here's a simplified
sorry for the stupid questions but there are just some things about WCF I
I don't know how to explain this correctly but just some sample for you
I have the following string: const char *str = \This is just some random
I have a relatively simple example of an MVC page that is using jQuery
I have not used PackedArray before, but just started looking at using them from
I'd hate to ask an intentionally subjective question on here, but I don't have
I had some existing VBA code that was building queries using string concatenation. I

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.