I have some doubts regarding the release of resources for cases where my modifiers are static.
My project is unit testing and I'm using Selenium for the first time.
public class LoginTest : Base
{
[ClassInitialize]
public static void Iniciar(TestContext context) { }
[TestMethod]
public void Logar()
{
var loginPage = new LoginPage(driverGC);
loginPage.Navegar("http://localhost:3533/Authorize/LogOn").Logar("[email protected]", "123456");
Assert.IsTrue(loginPage.VerificarMenuLateral());
}
...
}
public abstract class Base
{
protected static IWebDriver driverGC = new ChromeDriver(@"C:\chromedriver_win32");
}
The property is static so that all tests occur with reference to what has already been obtained and to not have new instances of the browser with each method executed. Is it a practice not recommended?
It turns out that I have several classes to test. All inheriting base. I have read in several places that static objects, methods, and classes are not released from memory in the normal GC process.
Does this mean that for every first test method executed in each class, will I have a memory load of the driverGC
property that will never be released?
Or, being the property of a class that is not static, will it be removed next to the class release?
Or, will this property come to the next class with the values obtained in the previous class execution?
Implemented within each test class a method:
[ClassCleanup]
public static void Finalizar()
{
driverGC.Close();
driverGC.Dispose();
}
Will this lead to memory leak after execution?
How do I track all objects loaded in memory at runtime and their respective releases? How?