JSTest.NET from Nuget integration with MS Test Series Part 5

This is part 5 of 6 posts, you can find the previous post here.

Integrating MS Test to execute the JavaScript test:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace WebPortal.Tests.JSTest
{
 [TestClass]
 public class FirstJavaScriptTests : JavaScriptTestBase
 {
  //Path of file name is critical here.
  private const string ProductionCodeFileName
  = @"..\..\..\..\WebPortal.Tests\SampleProduction.js";
  private const string TestCodeFileName
  = @"..\..\..\..\WebPortal.Tests\SampleTest.js";

  /// <summary>
  /// Setup is where you set Production files
  /// </summary>
  [TestInitialize]
  public void Setup()
  {
     AppendProdJavaScriptFile(ProductionCodeFileName);
  }

  [TestMethod]
  public void ReturnSumOfTwoNumber()
  {
     RunTest(TestCodeFileName, "returnSumOfTwoNumber");
  }
 }
}

Code is explained below:

  1. File names of JavaScript test file must be written as private class variable.
  2. Setup must load all production file.
  3. RunTest Method will be used to execute the Tests.

Read post 6 for the concluding guideline here.

2 comments

Leave a comment