D E V M A T E

Loading

Create your first Test

You are here:
Estimated reading time: 1 min

Let us create a simple example solution that demonstrates how to use devmate. For a more detailed example that actually shows the strengths of Equivalence Partitioning please refer to Chapter 3. We start by creating a .Net Core library project:

Let’s call the solution and the new library project “HelloWorld”

Then we add a unit tests project to the solution:

It is important that you select from either “NUnit Test Project”, “xUnit Test Project” or “MSTest Test Project” since devmate currently supports NUnit3, xUnit, and MSTest unit-testing frameworks. After adding the test-project your solution tree should look like this:

Now let us add a static method string Greet(string whom) to our library project:

namespace HelloWorld
{
        public static class Example
        {
            public static string Greet(string whom)
            {
                return $"Hello {whom}";
            }      
    }
}

To create a test model for this method just right-click inside the method and select “Test with devmate” from the context menu:

image2021-4-20_12-57-51.png

A file dialog will ask you where to store the new test-model. Store it somewhere in your test project:

image2020-10-14_13-48-23.png

Now the Equivalence Class Editor opens:

image2021-4-20_13-0-36.png

Let us add a representative to the equivalence class “valid” and set its value to “World”:

image2021-4-20_13-1-31.png
image2021-4-20_13-2-12.png

Now we are ready to generate test cases: Just click on “Generate Test Cases”. A single test with input factor “whom” set to “World” is created. Next set the expected value to “Hello World”. Your test model should look like this:

image2021-4-20_13-3-35.png

Finally you are set to generate unit tests. Click on “Generate NUnit Test Code” and store the test in your test-project:

image2021-4-20_13-5-24.png

That’s it. You just created your first unit test using devmate:

/*
* DO NOT MODIFY THIS COMMENT
* Generated by devmate
* Test model: 02f3de8a-bcd7-4ea3-81c1-6069425f6944
*/
 
using System;
using System.Collections.Generic;
using NUnit.Framework;
 
namespace HelloWorldTests
{
    public class GreetTestCase
    {
#region Test methods
        [Test]
        [TestCaseSource(nameof(ExpectedReturnValueTests))]
        public void GreetTest(ExpectedValueTestData<string> data)
        {
            var actual = HelloWorld.Example.Greet(data.Params.whom);
            Assert.AreEqual(data.ExpectedValue, actual);
        }
#endregion
 
#region Data
        private static IEnumerable<TestCaseData> ExpectedReturnValueTests()
        {
            yield return new TestCaseData(
                new ExpectedValueTestData<string>
                {
                    Params = new Parameters
                    {
                        whom = "World",
                    },
                    ExpectedValue = string.Empty,
                }).SetName(@"p1");
        }
#endregion
 
#region Types
        public struct ExpectedValueTestData<TExpected>
        {
            public Parameters Params;
            public TExpected ExpectedValue;
        }
 
        public struct Parameters
        {
            public string whom;
        }
#endregion
    }
}
 
/*
WARNING: Modification of this comment will make it impossible to merge user-defined changes
 
BEGIN_CODEGEN_DATA
H4sIAAAAAAAAAIVSXW/aQBB8NhL/YUVfTBSckJA0LSlqBE7CAxAVt1VV9eHwLYnVs8+5O0NQxX/vnj8Aq00rWdbt3sz
OztgnR83GEYxmMJ0FMJmNxrffILgfz2E4m0z8aWBv7zBBxQxyWGyA4yqms+0HqA3EkqN4D6dny3OOV6yzCPnbTg/Zee
eqG3Y7l6eX73pnF0t694hz0mw0G5mOkkeYb7TBuF8vvaEUAkMTyUR7uW4U7iDTz0lkvFvFYlxL9bNvZyVU6JSFCPcoh
PwqleB2L91s/Go2nDRbiCiEUDCt4U4hGns5ZJoMOAR4o/CRtEoraJ4kJ6bjfLeNH7uTJcxlpkJ0raBcuv5LSmsi/4Qm
U8kXJjLMZdvtnFXqrmTE97I70g4+YoZda6PI3QA4FW1Ltos7zoopYKHJmIAPB+Y8/4XFqUAvH+takvfAKBPtrZ9k3O7
n5ButURnvRqH/TBMKWE3+uBxeELYUBSa8SMPmWgVjN8wNqWhFnx20YYaMjf0ki+mnWAi8rgKy0AG8Fox7YG0ToeCgcg
QkuIbDEW4OcWz7n3kVsGKg4xQRUFKWlxdoUOnytkI5NiICtfIoW8dle1sdaoKEK6Q8P07NpsRs294czZTmux9babf1n
/yCTYr64I+giVloXnEWVO3BPquSt7dUHHX/8HZHrA+uVvtTv55QTanwDDapv1mzNT2/AfpH6/84BAAA
END_CODEGEN_DATA
*/

The full source code of this example is available on Github.

Was this article helpful?
Dislike 0
Views: 100

Continue reading

Previous: License
Next: Setup

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

GetResponse, Google Analytics

We use Google Analytics for marketing purposes. You can disable these cookies.
  • __utmz
  • __utma
  • _ga
  • _gat

We use GetResponse for marketing purposes. This service cannot be disabled, otherwise the website functions will be limited.

Decline all Services
Accept all Services
Get Free Access Now to
9 eBooks!
All about Automated Software Testing
Proven experts
Learn to save up to 75% of your test efforts
Get Free Access Now!
Get Access Now! & Save 50%
Personal Trainer FREE Nutrition Custom Workout App
Get Access Now!
eBook Download
Enter your details to get your free ebook!
All about Automated Software Testing
Download Free Ebook
SUBSCRIBE
MY WEB
NEWSLETTERS
Lorem ipsum dolor sit amet, consectetur adipiscing