Updated question ::
I want to set up data before any Test in the test suite is run using xUnit.net. I tried IUseFixture
but its run before any test class is run (not before the test suite)
Consider your suite has 2 test classes having 2 tests/class, when tried with IUseFixture
, SetFixture
runs 4 times (once per test).
I need something that run only once when all the four tests run simultaneously (once per test suite)... , here is the example (using WebDriver/C#/xunit)::
Class 1:
public class Class1 : IUseFixture<BrowserFixture>
{
private IWebDriver driver;
public void SetFixture(BrowserFixture data)
{
driver = data.InitiateDriver();
Console.WriteLine("SetFixture Called");
}
public Class1()
{
Console.WriteLine("Test Constructor is Called");
}
[Fact]
public void Test()
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Id("gbqfq")).SendKeys("Testing");
}
[Fact]
public void Test2()
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Id("gbqfq")).SendKeys("Testing again");
}
}
Class 2 :
public class Class2 : IUseFixture<BrowserFixture>
{
private IWebDriver driver;
public void SetFixture(BrowserFixture data)
{
driver = data.InitiateDriver();
Console.WriteLine("SetFixture Called");
}
public Class2()
{
Console.WriteLine("Test Constructor is Called");
}
[Fact]
public void Test3()
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Id("gbqfq")).SendKeys("Testing");
}
[Fact]
public void Test4()
{
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Id("gbqfq")).SendKeys("Testing again");
}
}
Fixture Class ::
public class BrowserFixture
{
private IWebDriver driver;
public BrowserFixture()
{
driver = new FirefoxDriver();
}
public IWebDriver InitiateDriver()
{
return driver;
}
}
Now when i run Test,Test2,Test3,Test4 simultaneously , SetFixture is called 4 times , i need something that run only once before any test run (once per test suite) or i can say something that run only once before any of the test class in the TestSuite is intialized , something like BeforeSuite in TestNG ::
http://testng.org/javadoc/org/testng/annotations/BeforeSuite.html http://testng.org/doc/documentation-main.html#annotations