2
I’m having some doubts regarding the release of resources for cases where my modifiers are static.
My project is unit test 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 there are no new instances of the browser for each method executed. It is a practice not recommended?
I happen to have several classes for testing. All inheriting base. I read in various places that static objects, methods and classes are not released from memory in the normal GC process.
This means that for each first test method run in each class, I will have a load in the memory of the property driverGC
that will never be released?
Or, being the property of a class that is not static, it will be removed along with the class release?
Or, this property will come to the next class with the values obtained in the execution of the previous class?
I implemented within each test class a method:
[ClassCleanup]
public static void Finalizar()
{
driverGC.Close();
driverGC.Dispose();
}
This will lead to memory release after execution?
How do I track all the objects loaded in memory at runtime and their respective releases? Is there a way?
Did the answer resolve what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?
– Maniero