Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test names #100

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
80 changes: 58 additions & 22 deletions Tests/UnitTestsSerialPort/SerialTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

using nanoFramework.Hardware.Esp32;
using nanoFramework.TestFramework;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using nanoFramework.TestFramework;

// The following dependenies are target or platform dependent (comment out if required and remove nuget).
using nanoFramework.Hardware.Esp32;

namespace UnitTestsSerialPort
{
Expand All @@ -20,8 +20,9 @@ public class SerialTests
static SerialPort _serOne;
static SerialPort _serTwo;

// The default test setup is for an ESP32
[Setup]
public void SetupComPorts()
public void SetupComPorts_ESP32()
{
OutputHelper.WriteLine("Setting up tests for an ESP32...");
try
Expand All @@ -40,8 +41,8 @@ public void SetupComPorts()
OutputHelper.WriteLine("You will need to connect:");
OutputHelper.WriteLine(" COM2 RX <-> COM3 TX");
OutputHelper.WriteLine(" COM2 TX <-> COM3 RX");
OutputHelper.WriteLine(" COM2 RTS <-> COM3 CTS");
OutputHelper.WriteLine(" COM2 CTS <-> COM3 RTS");
OutputHelper.WriteLine(" COM2 RTS <-> COM3 CTS"); // TODO: Optional?!
OutputHelper.WriteLine(" COM2 CTS <-> COM3 RTS"); // TODO: Optional?!
_serOne = new SerialPort("COM2");
_serTwo = new SerialPort("COM3");
OutputHelper.WriteLine("SerialPorts created, trying to open them");
Expand All @@ -61,8 +62,43 @@ public void SetupComPorts()
}
}

// This commented out method is provided as an example of how to "setup" a different target board.
// in this case, an STM32F769I.
// When uncommened, other setup methods (such as `SetupComPorts_ESP32()`) should be removed.
//[Setup]
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
//public void SetupComPorts_ChibOs_STM32F769I_Disco()
//{
// OutputHelper.WriteLine("Setting up tests for an STM32F769I...");
// try
// {
// Debug.WriteLine("Please adjust for your own usage. If you need another hardware, please add the proper nuget and adjust as well");

// OutputHelper.WriteLine("You will need to connect:");
// OutputHelper.WriteLine(" COM5 (PD2) RX <-> COM6 (PC6) TX");
// OutputHelper.WriteLine(" COM5 (PC12) TX <-> COM6 (PC7) RX");
// // OutputHelper.WriteLine(" COM5 RTS <-> COM6 CTS");
// // OutputHelper.WriteLine(" COM5 CTS <-> COM6 RTS");
// _serOne = new SerialPort("COM5");
// _serTwo = new SerialPort("COM6");
// OutputHelper.WriteLine("SerialPorts created, trying to open them");
// _serOne.Open();
// OutputHelper.WriteLine("SerialPort One COM5 opened");
// _serTwo.Open();
// OutputHelper.WriteLine("SerialPort Two COM6 opened");
// OutputHelper.WriteLine("SarialPorts opened, will close them");
// // Wait a bit just to make sure and close them all
// Thread.Sleep(100);
// EnsurePortsClosed();
// OutputHelper.WriteLine("SerialPorts Closed.");
// }
// catch
// {
// Assert.SkipTest("Serial Ports not supported in this platform or not properly configured");
// }
//}

[TestMethod]
public void GetPortNamesTest()
public void GetAllAvailableSerialPortNames()
{
var ports = SerialPort.GetPortNames();
OutputHelper.WriteLine("Available SerialPorts:");
Expand All @@ -73,7 +109,7 @@ public void GetPortNamesTest()
}

[TestMethod]
public void BasicReadWriteTests()
public void WriteAndReadFourBytes()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -113,7 +149,7 @@ public void VerifyDefaultReadLineCharacter()
}

[TestMethod]
public void WriteAndReadStringTests()
public void WriteAndReadSimpleAsciiString_37Chars()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -130,7 +166,7 @@ public void WriteAndReadStringTests()
}

[TestMethod]
public void ReadMultipleLinesTests()
public void WriteAndReadMultipleLineAsciiString()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -151,7 +187,7 @@ public void ReadMultipleLinesTests()
}

[TestMethod]
public void CheckReadByteSize()
public void CheckReadByteSizeUtf8String()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -190,7 +226,7 @@ public void CheckReadLineWithoutAnything()
}

[TestMethod]
public void CheckReadTimeoutTest()
public void CheckReadTimeout()
{
Assert.Throws(typeof(TimeoutException), () =>
{
Expand All @@ -206,7 +242,7 @@ public void CheckReadTimeoutTest()
}

[TestMethod]
public void ReadByteWriteByteTests()
public void WriteThreeBytesReadSingleByte()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -229,7 +265,7 @@ public void ReadByteWriteByteTests()
}

[TestMethod]
public void CheckBytesAvailableTest()
public void CheckBytesAreAvailable()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -268,7 +304,7 @@ public void TryReadWriteWhileClosed()
}

[TestMethod]
public void AdjustBaudRateTests()
public void AdjustBaudRateTo115200()
{
// Arrange
_serOne.BaudRate = 115200;
Expand All @@ -278,7 +314,7 @@ public void AdjustBaudRateTests()
}

[TestMethod]
public void AdjustHandshakeTests()
public void AdjustHandshakeRTS()
{
// Arrange
_serOne.Handshake = Handshake.RequestToSend;
Expand All @@ -291,7 +327,7 @@ public void AdjustHandshakeTests()
}

[TestMethod]
public void TestStreams()
public void StreamsCanWriteRead()
{
// Arrange
EnsurePortsOpen();
Expand All @@ -317,7 +353,7 @@ public void TestStreams()
}

[TestMethod]
public void TestEvents()
public void DataReceivedEventsAreGenerated()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -345,7 +381,7 @@ private void DataReceivedNormalEventTest(object sender, SerialDataReceivedEventA
}

[TestMethod]
public void TestWatchCharEvents()
public void WatchCharEventsAreGenerated()
{
// Arrange
EnsurePortsOpen();
Expand Down Expand Up @@ -390,7 +426,7 @@ private void SendAndReceiveBasic()
}

[Cleanup]
public void CleanPorts()
public void DisposeSerialPorts()
{
EnsurePortsClosed();
_serOne.Dispose();
Expand Down