MStest založení projektu
+Nainstalovat do PC:
+-
+
- .NET 7.0 nebo 6.0 s dlouhou podporou +
- Visual Studio Code +
- nebo +
- Visual Studio 2022 – pouze WIN a MacOS +
Potřebná rozšíření ve VS Code:
+-
+
- .NET Extension Pack +
- C# +
- Nuget Package Manager +
Postup v VSCode:
+Založení nového projektu ve Visual Studio Code:
+-
+
- dotnet new mstest -n MyTestProject +
- dotnet add package Microsoft.NET.Test.Sdk +
- dotnet add package MSTest.TestFramework +
Stažení Selenia (stahne potřebý základ):
+V terminálu musíme do složky projektu co vytvořila dotnet new + mstest
+-
+
- dotnet add package Selenium.WebDriver + +
Test se spustí:
+-
+
- dotnet test +
- nebo za pomocí +
- dotnet watch který sám automaticky sleduje změny v kódu a je schopný + spustit testy +
Tento návod funguje jak pod Linux (odzkoušené v distribucích EndeavorOS,Ubuntu 22.04), MacOS, Windows + 11.
+ +Příklad testu:
+-
+
- using Microsoft.VisualStudio.TestTools.UnitTesting; +
- using OpenQA.Selenium; +
- using OpenQA.Selenium.Chrome; +
- namespace MyTestProject +
- { +
- [TestClass] +
- public class UnitTest1 +
- { +
- [TestMethod] +
- public void TestMethod1() +
- { +
- string expectedTitle = "O mně - Lukáš bloguje"; +
- string actualTitle = ""; +
- IWebDriver driver = new ChromeDriver(); +
- driver.Navigate().GoToUrl("https://lukaskanka.cz/"); +
- IWebElement tlačítko = driver.FindElement(By.Id("xPath tlačítka")); +
- tlačítko.Click(); +
- expectedTitle = "O mně - Lukáš bloguje"; +
- actualTitle = driver.Title; +
- Assert.AreEqual(expectedTitle, actualTitle, "Title does not match"); +
- } +
- } +
- } +