How to use SourceData class of NUnit.TestData.TestFixtureSourceData package

Best Nunit code snippet using NUnit.TestData.TestFixtureSourceData.SourceData

TestFixtureSourceData.cs

Source:TestFixtureSourceData.cs Github

copy

Full Screen

...22// ***********************************************************************23using System.Collections;24using NUnit.Framework;25using NUnit.Framework.Internal;26namespace NUnit.TestData.TestFixtureSourceData27{28 public abstract class TestFixtureSourceTest29 {30 private string Arg;31 private string Expected;32 public TestFixtureSourceTest(string arg, string expected)33 {34 Arg = arg;35 Expected = expected;36 }37 [Test]38 public void CheckSource()39 {40 Assert.That(Arg, Is.EqualTo(Expected));41 }42 }43 public abstract class TestFixtureSourceDivideTest44 {45 private int X;46 private int Y;47 private int Z;48 public TestFixtureSourceDivideTest(int x, int y, int z)49 {50 X = x;51 Y = y;52 Z = z;53 }54 [Test]55 public void CheckSource()56 {57 Assert.That(X / Y, Is.EqualTo(Z));58 }59 }60 [TestFixtureSource("StaticField")]61 public class StaticField_SameClass : TestFixtureSourceTest62 {63 public StaticField_SameClass(string arg) : base(arg, "StaticFieldInClass") { }64 static object[] StaticField = new object[] { "StaticFieldInClass" };65 }66 [TestFixtureSource("StaticProperty")]67 public class StaticProperty_SameClass : TestFixtureSourceTest68 {69 public StaticProperty_SameClass(string arg) : base(arg, "StaticPropertyInClass") { }70 public StaticProperty_SameClass(string arg, string expected) : base(arg, expected) { }71 public static object[] StaticProperty72 {73 get { return new object[] { new object[] { "StaticPropertyInClass" } }; }74 }75 }76 [TestFixtureSource("StaticProperty")]77 public class StaticProperty_InheritedClass : StaticProperty_SameClass 78 {79 public StaticProperty_InheritedClass (string arg) : base(arg, "StaticPropertyInClass") { }80 }81 [TestFixtureSource("StaticMethod")]82 public class StaticMethod_SameClass : TestFixtureSourceTest83 {84 public StaticMethod_SameClass(string arg) : base(arg, "StaticMethodInClass") { }85 static object[] StaticMethod()86 {87 return new object[] { new object[] { "StaticMethodInClass" } };88 }89 }90 [TestFixtureSource("InstanceField")]91 public class InstanceField_SameClass : TestFixtureSourceTest92 {93 public InstanceField_SameClass(string arg) : base(arg, "InstanceFieldInClass") { }94 object[] InstanceField = new object[] { "InstanceFieldInClass" };95 }96 [TestFixtureSource("InstanceProperty")]97 public class InstanceProperty_SameClass : TestFixtureSourceTest98 {99 public InstanceProperty_SameClass(string arg) : base(arg, "InstancePropertyInClass") { }100 object[] InstanceProperty101 {102 get { return new object[] { new object[] { "InstancePropertyInClass" } }; }103 }104 }105 [TestFixtureSource("InstanceMethod")]106 public class InstanceMethod_SameClass : TestFixtureSourceTest107 {108 public InstanceMethod_SameClass(string arg) : base(arg, "InstanceMethodInClass") { }109 object[] InstanceMethod()110 {111 return new object[] { new object[] { "InstanceMethodInClass" } };112 }113 }114 [TestFixtureSource(typeof(SourceData), "StaticField")]115 public class StaticField_DifferentClass : TestFixtureSourceTest116 {117 public StaticField_DifferentClass(string arg) : base(arg, "StaticField") { }118 }119 [TestFixtureSource(typeof(SourceData), "StaticProperty")]120 public class StaticProperty_DifferentClass : TestFixtureSourceTest121 {122 public StaticProperty_DifferentClass(string arg) : base(arg, "StaticProperty") { }123 }124 [TestFixtureSource(typeof(SourceData), "StaticMethod")]125 public class StaticMethod_DifferentClass : TestFixtureSourceTest126 {127 public StaticMethod_DifferentClass(string arg) : base(arg, "StaticMethod") { }128 }129 [TestFixtureSource(typeof(SourceData_IEnumerable))]130 public class IEnumerableSource : TestFixtureSourceTest131 {132 public IEnumerableSource(string arg) : base(arg, "SourceData_IEnumerable") { }133 }134 [TestFixtureSource("MyData")]135 public class SourceReturnsObjectArray : TestFixtureSourceDivideTest136 {137 public SourceReturnsObjectArray(int x, int y, int z) : base(x, y, z) { }138 static IEnumerable MyData()139 {140 yield return new object[] { 12, 4, 3 };141 yield return new object[] { 12, 3, 4 };142 yield return new object[] { 12, 6, 2 };143 }144 }145 [TestFixtureSource("MyData")]146 public class SourceReturnsFixtureParameters : TestFixtureSourceDivideTest147 {148 public SourceReturnsFixtureParameters(int x, int y, int z) : base(x, y, z) { }149 static IEnumerable MyData()150 {151 yield return new TestFixtureParameters(12, 4, 3);152 yield return new TestFixtureParameters(12, 3, 4);153 yield return new TestFixtureParameters(12, 6, 2);154 }155 }156 [TestFixture]157 [TestFixtureSource("MyData")]158 public class ExtraTestFixtureAttributeIsIgnored : TestFixtureSourceDivideTest159 {160 public ExtraTestFixtureAttributeIsIgnored(int x, int y, int z) : base(x, y, z) { }161 static IEnumerable MyData()162 {163 yield return new object[] { 12, 4, 3 };164 yield return new object[] { 12, 3, 4 };165 yield return new object[] { 12, 6, 2 };166 }167 }168 [TestFixture]169 [TestFixtureSource("MyData")]170 [TestFixtureSource("MoreData", Category = "Extra")]171 [TestFixture(12, 12, 1)]172 public class TestFixtureMayUseMultipleSourceAttributes : TestFixtureSourceDivideTest173 {174 public TestFixtureMayUseMultipleSourceAttributes(int n, int d, int q) : base(n, d, q) { }175 static IEnumerable MyData()176 {177 yield return new object[] { 12, 4, 3 };178 yield return new object[] { 12, 3, 4 };179 yield return new object[] { 12, 6, 2 };180 }181 static object[] MoreData = new object[] {182 new object[] { 12, 1, 12 },183 new object[] { 12, 2, 6 } };184 }185 [TestFixtureSource("IgnoredData")]186 public class IndividualInstancesMayBeIgnored : TestFixtureSourceTest187 {188 public IndividualInstancesMayBeIgnored(string arg) : base(arg, "IgnoredData") { }189 static IEnumerable IgnoredData()190 {191 yield return new TestFixtureData("GoodData");192 yield return new TestFixtureData("IgnoredData").Ignore("There must be a reason");193 yield return new TestFixtureData("MoreGoodData");194 }195 }196 [TestFixtureSource("ExplicitData")]197 public class IndividualInstancesMayBeExplicit : TestFixtureSourceTest198 {199 public IndividualInstancesMayBeExplicit(string arg) : base(arg, "ExplicitData") { }200 static IEnumerable ExplicitData()201 {202 yield return new TestFixtureData("GoodData");203 yield return new TestFixtureData("ExplicitData").Explicit("Runs long");204 yield return new TestFixtureData("MoreExplicitData").Explicit();205 }206 }207 [TestFixture]208 public abstract class Issue1118_Root209 {210 protected readonly string Browser;211 protected Issue1118_Root(string browser)212 {213 Browser = browser;214 }215 [SetUp]216 public void Setup()217 {218 }219 }220 [TestFixtureSource(typeof(Issue1118_SourceData))]221 public class Issue1118_Base : Issue1118_Root222 {223 public Issue1118_Base(string browser) : base(browser)224 {225 }226 [TearDown]227 public void Cleanup()228 {229 }230 }231 public class Issue1118_Fixture : Issue1118_Base232 {233 public Issue1118_Fixture(string browser) : base(browser)234 {235 }236 [Test]237 public void DoSomethingOnAWebPageWithSelenium()238 {239 }240 [Test]241 public void DoSomethingElseOnAWebPageWithSelenium()242 {243 }244 }245 public class Issue1118_SourceData : IEnumerable246 {247 public IEnumerator GetEnumerator()248 {249 yield return "Firefox";250 yield return "Chrome";251 yield return "Internet Explorer";252 }253 }254 #region Source Data Classes255 class SourceData_IEnumerable : IEnumerable256 {257 public SourceData_IEnumerable()258 {259 }260 public IEnumerator GetEnumerator()261 {262 yield return "SourceData_IEnumerable";263 }264 }265 class SourceData266 {267 public static object[] InheritedStaticProperty268 {269 get { return new object[] { new object[] { "StaticProperty" } }; }270 }271 static object[] StaticField = new object[] { "StaticField" };272 static object[] StaticProperty273 {274 get { return new object[] { new object[] { "StaticProperty" } }; }275 }276 static object[] StaticMethod()277 {278 return new object[] { new object[] { "StaticMethod" } };279 }...

Full Screen

Full Screen

SourceData

Using AI Code Generation

copy

Full Screen

1using NUnit.TestData.TestFixtureSourceData;2using NUnit.Framework;3{4 {5 {6 {7 return new object[] { new object[] { 1, 2 }, new object[] { 3, 4 } };8 }9 }10 }11}12using NUnit.TestData.TestFixtureSourceData;13using NUnit.Framework;14{15 [TestFixtureSource(typeof(SourceData), "Source")]16 {17 int x;18 int y;19 public TestFixtureSource(int x, int y)20 {21 this.x = x;22 this.y = y;23 }24 public void Test()25 {26 Assert.AreEqual(x + y, 3);27 }28 }29}30Results (nunit3) saved as TestResult.xml31public TestFixtureSource(int x, int y)32{33 this.x = x;34 this.y = y;35}

Full Screen

Full Screen

SourceData

Using AI Code Generation

copy

Full Screen

1using NUnit.TestData.TestFixtureSourceData;2using NUnit.Framework;3{4 {5 {6 new object[] { 1, 2, 3 },7 new object[] { 5, 6, 11 },8 new object[] { 7, 8, 15 }9 };10 }11}12using NUnit.TestData.TestFixtureSourceData;13using NUnit.Framework;14{15 {16 {17 new object[] { 1, 2, 3 },18 new object[] { 5, 6, 11 },19 new object[] { 7, 8, 15 }20 };21 }22}23using NUnit.TestData.TestFixtureSourceData;24using NUnit.Framework;25{26 {27 {28 new object[] { 1, 2, 3 },29 new object[] { 5, 6, 11 },30 new object[] { 7, 8, 15 }31 };32 }33}34using NUnit.TestData.TestFixtureSourceData;35using NUnit.Framework;36{37 {38 {39 new object[] { 1, 2, 3 },40 new object[] { 5, 6, 11 },41 new object[] { 7, 8, 15 }42 };43 }44}45using NUnit.TestData.TestFixtureSourceData;46using NUnit.Framework;47{48 {49 {50 new object[] { 1,

Full Screen

Full Screen

SourceData

Using AI Code Generation

copy

Full Screen

1using NUnit.TestData.TestFixtureSourceData;2using NUnit.Framework;3{4 {5 public static int[] IntData = { 1, 2, 3 };6 public static string[] StringData = { "One", "Two", "Three" };7 }8}9using NUnit.TestData.TestFixtureSourceData;10using NUnit.Framework;11{12 {13 public static int[] IntData = { 1, 2, 3 };14 public static string[] StringData = { "One", "Two", "Three" };15 }16}17using NUnit.TestData.TestFixtureSourceData;18using NUnit.Framework;19{20 {21 public static int[] IntData = { 1, 2, 3 };22 public static string[] StringData = { "One", "Two", "Three" };23 }24}25using NUnit.TestData.TestFixtureSourceData;26using NUnit.Framework;27{28 {29 public static int[] IntData = { 1, 2, 3 };30 public static string[] StringData = { "One", "Two", "Three" };31 }32}33using NUnit.TestData.TestFixtureSourceData;34using NUnit.Framework;35{36 {37 public static int[] IntData = { 1, 2, 3 };38 public static string[] StringData = { "One", "Two", "Three" };39 }40}41using NUnit.TestData.TestFixtureSourceData;42using NUnit.Framework;43{

Full Screen

Full Screen

SourceData

Using AI Code Generation

copy

Full Screen

1using NUnit.TestData.TestFixtureSourceData;2using NUnit.Framework;3{4 [TestFixtureSource(typeof(SourceData), "Data")]5 {6 private int _value;7 public TestFixtureSourceTests(int value)8 {9 _value = value;10 }11 public void Test()12 {13 Assert.AreEqual(5, _value);14 }15 }16}17using NUnit.TestData.TestFixtureSourceData;18using NUnit.Framework;19{20 [TestFixtureSource(typeof(SourceData), "Data")]21 {22 private int _value;23 public TestFixtureSourceTests(int value)24 {25 _value = value;26 }27 public void Test()28 {29 Assert.AreEqual(6, _value);30 }31 }32}33using NUnit.TestData.TestFixtureSourceData;34using NUnit.Framework;35{36 [TestFixtureSource(typeof(SourceData), "Data")]37 {38 private int _value;39 public TestFixtureSourceTests(int value)40 {41 _value = value;42 }43 public void Test()44 {45 Assert.AreEqual(7, _value);46 }47 }48}49using NUnit.TestData.TestFixtureSourceData;50using NUnit.Framework;51{52 [TestFixtureSource(typeof(SourceData), "Data")]53 {54 private int _value;55 public TestFixtureSourceTests(int value)56 {57 _value = value;58 }59 public void Test()60 {61 Assert.AreEqual(8, _value);62 }63 }64}65using NUnit.TestData.TestFixtureSourceData;66using NUnit.Framework;67{68 [TestFixtureSource(typeof(SourceData), "Data")]

Full Screen

Full Screen

SourceData

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework;2using NUnit.TestData.TestFixtureSourceData;3{4 {5 public static object[] GetSourceData()6 {7 object[] data = new object[2];8 data[0] = new object[] { 5, 10 };9 data[1] = new object[] { 10, 20 };10 return data;11 }12 }13}14using NUnit.Framework;15using NUnit.TestData.TestFixtureSourceData;16{17 {18 public static object[] GetSourceData()19 {20 object[] data = new object[2];21 data[0] = new object[] { 5, 10 };22 data[1] = new object[] { 10, 20 };23 return data;24 }25 }26}27using NUnit.Framework;28using NUnit.TestData.TestFixtureSourceData;29{30 {31 public static object[] GetSourceData()32 {33 object[] data = new object[2];34 data[0] = new object[] { 5, 10 };35 data[1] = new object[] { 10, 20 };36 return data;37 }38 }39}40using NUnit.Framework;41using NUnit.TestData.TestFixtureSourceData;42{43 {44 public static object[] GetSourceData()45 {

Full Screen

Full Screen

SourceData

Using AI Code Generation

copy

Full Screen

1using NUnit.Framework;2using NUnit.TestData.TestFixtureSourceData;3using System;4using System.Collections;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 {12 {13 yield return new TestCaseData(1, 2, 3);14 yield return new TestCaseData(2, 3, 5);15 yield return new TestCaseData(3, 4, 7);16 }17 }18 }19}20using NUnit.Framework;21using NUnit.TestData.TestFixtureSourceData;22using System;23using System.Collections;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28{29 {30 {31 {32 yield return new TestCaseData(1, 2, 3);33 yield return new TestCaseData(2, 3, 5);34 yield return new TestCaseData(3, 4, 7);35 }36 }37 }38}39using NUnit.Framework;40using NUnit.TestData.TestFixtureSourceData;41using System;42using System.Collections;43using System.Collections.Generic;44using System.Linq;45using System.Text;46using System.Threading.Tasks;47{48 {49 {50 {51 yield return new TestCaseData(1,

Full Screen

Full Screen

Nunit tutorial

Nunit is a well-known open-source unit testing framework for C#. This framework is easy to work with and user-friendly. LambdaTest’s NUnit Testing Tutorial provides a structured and detailed learning environment to help you leverage knowledge about the NUnit framework. The NUnit tutorial covers chapters from basics such as environment setup to annotations, assertions, Selenium WebDriver commands, and parallel execution using the NUnit framework.

Chapters

  1. NUnit Environment Setup - All the prerequisites and setup environments are provided to help you begin with NUnit testing.
  2. NUnit With Selenium - Learn how to use the NUnit framework with Selenium for automation testing and its installation.
  3. Selenium WebDriver Commands in NUnit - Leverage your knowledge about the top 28 Selenium WebDriver Commands in NUnit For Test Automation. It covers web browser commands, web element commands, and drop-down commands.
  4. NUnit Parameterized Unit Tests - Tests on varied combinations may lead to code duplication or redundancy. This chapter discusses how NUnit Parameterized Unit Tests and their methods can help avoid code duplication.
  5. NUnit Asserts - Learn about the usage of assertions in NUnit using Selenium
  6. NUnit Annotations - Learn how to use and execute NUnit annotations for Selenium Automation Testing
  7. Generating Test Reports In NUnit - Understand how to use extent reports and generate reports with NUnit and Selenium WebDriver. Also, look into how to capture screenshots in NUnit extent reports.
  8. Parallel Execution In NUnit - Parallel testing helps to reduce time consumption while executing a test. Deep dive into the concept of Specflow Parallel Execution in NUnit.

NUnit certification -

You can also check out the LambdaTest Certification to enhance your learning in Selenium Automation Testing using the NUnit framework.

YouTube

Watch this tutorial on the LambdaTest Channel to learn how to set up the NUnit framework, run tests and also execute parallel testing.

Run Nunit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in SourceData

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful