Create a .NET project without and IDE

With .NET 6 or later, you can create NUnit 3 or MSTest 3 testing projects without an IDE, using the installed templates. This enables you to create .NET projects on Linux OS as well as Windows OS.

Create a project

To list all available UFTd templates, run the following command:

dotnet new list uftd

To create new projects, run one of the following commands:

  • dotnet new uftd-mstest -n YourMSTestProjectName
  • dotnet new uftd-nunit3 -n YourNUnitProjectName

Back to top

Project template content for .NET 6 or later

The NUnit/MSTest UFT Developer project templates include the following:

  • Reference to the HP.LFT.SDK and related HP.LFT.* elements

  • Reference to Microsoft.CSharp and, for OpenText Functional Testing for Developers NUnit projects, nunit.framework

  • App.config, which enables you to customize some test settings. For details, see Customize test settings.
  • A basic UftDeveloperTest.cs template where you write your code.

    You can include multiple tests in one class, and you can use the Object Identification Center or Test Recorder to help generate the code.

    The exact structure of this template depends on whether you are using NUnit or MSTest. In both cases, they include attributes where you can define:

    Attribute Description
    Setup code Runs once at the start of the class
    Setup code Runs once at the start of each test
    Individual test units
    • The template includes a single [Test] (NUnit) / [TestMethod] (MSTest) attribute containing an empty Test() / TestMethod() method. You can rename this method to whatever you want to call your test.
    • You can add multiple [Test] / [TestMethod] attributes if you want to include several tests in your class.
    • Each [Test] / [TestMethod] attribute should declare a void test method that contains the main code for that test.
    Cleanup code Runs at the conclusion of each test
    Cleanup code Runs once at the end of the class
  • UnitTestClassBase.cs, which controls what happens during the different phases of your run, including running and closing the runtime engine.

This is an example from an NUnit 3 project:

  • For details on using the MSTest framework, see the relevant MSDN documentation.
  • For details on using the NUnit 3 framework, see the NUnit 3 documentation.

Back to top

Testing images in web applications

When you test images in web applications, use the Microsoft System.Drawing API to access GDI+ graphics functionality.

On Linux, this API is not supported for .NET versions 7 and later. Instead, you can use the HP.LFT.Common.Linux.Drawing API. For details, see the Linux.Drawing API reference.

Tip: For .NET 6, consult the Microsoft online documentation to enable using the System.Drawing API on a Linux machine, or use the Linux.Drawing API.

Back to top

To run MSTest test iterations with dynamic data

In .NET Framework, you could use a Context object/property that contained all the data to use when running the test. For .NET, we recommend the following solutions within the .NET Core API:

Windows: Use the DataSourceAttribute.

Linux: Use the DataTest methods. For example: DynamicData(nameof(TestDataSources.GetAddTestData), typeof(TestDataSources), DynamicDataSourceType.Method)]

The BaseClass created by the templates includes examples for these methods and attributes.

The following code sample demonstrates the use of the DataTest methods, providing 3 different data sets to use in 3 iterations. This sample provides the data in a table, but you could retrieve it from any data source, such as a database, Excel, or a text file. .

Copy code
[DataTestMethod]
[DynamicData(nameof(TestDataSources.GetAddTestData), typeof(TestDataSources), DynamicDataSourceType.Method)]
public void AddTest(int a, int b, int expectedSum)
{
    int actualSum = a + b;
    Assert.AreEqual(expectedSum, actualSum);
}

public static class TestDataSources
{
    public static IEnumerable<object[]> GetAddTestData()
    {
        return new List<object[]>
        {
            new object[] { 1, 2, 3 },
            new object[] { 3, 3, 6 },
            new object[] { 4, 5, 9 }
        };
    }
    ……
}
…..

Back to top

Next steps: