Recommended Unit Test Frameworks
The following unit test frameworks are recommended but not mandatory.
GoogleTest
Used for example in the Control Software stream, e.g. for Next Generation control development using C++.
Example of a unit test:
TEST(GTestCaseClass, TestFibonacci) {
TEST_ID("001");
TEST_DESCRIPTION("Test of Fibonacci property");
TEST_EXPECTED_RESULT("The correct fibonacci number is returned for position 1-3.");
// Setup
EngineerSw engineer = EngineerSw(1);
// Test and verify
// Stops current function.
// Use when continuing after failure doesn't make sense
ASSERT_EQ(1, engineer.fibonacci(1));
// Use when you want the test to continue to reveal more errors after the assertion failure
EXPECT_EQ(1, engineer.fibonacci(2));
EXPECT_EQ(2, engineer.fibonacci(3));
}
xUnit
Used for example in the Operations stream for Next Generation HMI development, e.g. in backend services written with C#.
Example of a unit test:
[Fact]
public void GetBinGraphic200_Test()
{
// Arrange
var filename = "test";
var binGraphic = new BinGraphic() { Name = "test", BinGraphicStream = new byte[0] };
this.DbContext.BinGraphics.Add(binGraphic);
this.DbContext.SaveChanges();
var expected = new MemoryStream(binGraphic.BinGraphicStream, 0, binGraphic.BinGraphicStream.Length);
// Act
var controller = new LooxWasmController(logger, this.DbContext, this.testValuesSource.Object, simulationConfig);
var resultAPI = controller.GetBinGraphic(filename) as FileStreamResult;
var result = new MemoryStream();
resultAPI.FileStream.CopyTo(result);
// Assert
Assert.True(expected.ToArray().Equals(result.ToArray()));
}
Jest
Used for example in the Operations stream for Next Generation HMI development, e.g. in frontend services written with Typescript Javascript.
Example of a unit test:
describe('LooxAPIService', () => {
test('Should correctly fetch graphics list', async () => {
// Arrange and Act
looxService.url = "test";
let graphicsList = await looxService.getGraphicsList();
// Assert
expect(graphicsList).toEqual(lastFetch);
});
MSTest
Used for example in the Operations stream for Symphony Plus, e.g. in backend services written with C#.
Example of a unit test:
[TestMethod]
[Description("Check Quality is expected")]
public void SamplingListTest_AverageQuality()
{
//PREPARATION
DateTime normalizeddt = DateTime.UtcNow;
normalizeddt = normalizeddt.AddSeconds(-normalizeddt.Second);
List<SPlusValue> values = new List<SPlusValue>();
SPlusValue testvalue = new SPlusValue
{
Dt = normalizeddt.AddMinutes(-5),
Value = 1,
Qual = SPlusQuality.Channelfailure
};
values.Add(testvalue);
testvalue = new SPlusValue
{
Dt = normalizeddt.AddMinutes(-3),
Value = 1000,
Qual = SPlusQuality.Good
};
values.Add(testvalue);
//ACT - FUNCTION TO BE TESTED
List<SPlusValue> t = SamplerGenerator.AverageSamplingList(values, normalizeddt.AddMinutes(-6), normalizeddt.AddMinutes(-1), 300);
//ASSERT
Assert.AreEqual(t?[1]?.Qual, SPlusQuality.Channelfailure);
}
Owner: Software Development Team