Created
July 9, 2015 19:50
-
-
Save angelovstanton/d7447f2b8ced86cb43b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestClass] | |
public class BaseTest | |
{ | |
private readonly ITestExecutionSubject currentTestExecutionSubject; | |
private TestContext testContextInstance; | |
public BaseTest() | |
{ | |
this.currentTestExecutionSubject = new MSTestExecutionSubject(); | |
this.InitializeTestExecutionBehaviorObservers(this.currentTestExecutionSubject); | |
var memberInfo = MethodInfo.GetCurrentMethod(); | |
this.currentTestExecutionSubject.TestInstantiated(memberInfo); | |
} | |
public string BaseUrl { get; set; } | |
public IWebDriver Browser { get; set; } | |
public TestContext TestContext | |
{ | |
get | |
{ | |
return testContextInstance; | |
} | |
set | |
{ | |
testContextInstance = value; | |
} | |
} | |
public string TestName | |
{ | |
get | |
{ | |
return this.TestContext.TestName; | |
} | |
} | |
[ClassInitialize] | |
public static void OnClassInitialize(TestContext context) | |
{ | |
} | |
[ClassCleanup] | |
public static void OnClassCleanup() | |
{ | |
} | |
[TestInitialize] | |
public void CoreTestInit() | |
{ | |
var memberInfo = GetCurrentExecutionMethodInfo(); | |
this.currentTestExecutionSubject.PreTestInit(this.TestContext, memberInfo); | |
this.TestInit(); | |
this.currentTestExecutionSubject.PostTestInit(this.TestContext, memberInfo); | |
} | |
[TestCleanup] | |
public void CoreTestCleanup() | |
{ | |
var memberInfo = GetCurrentExecutionMethodInfo(); | |
this.currentTestExecutionSubject.PreTestCleanup(this.TestContext, memberInfo); | |
this.TestCleanup(); | |
this.currentTestExecutionSubject.PostTestCleanup(this.TestContext, memberInfo); | |
} | |
public virtual void TestInit() | |
{ | |
} | |
public virtual void TestCleanup() | |
{ | |
} | |
private MethodInfo GetCurrentExecutionMethodInfo() | |
{ | |
var memberInfo = this.GetType().GetMethod(this.TestContext.TestName); | |
return memberInfo; | |
} | |
private void InitializeTestExecutionBehaviorObservers(ITestExecutionSubject currentTestExecutionSubject) | |
{ | |
new AssociatedBugTestBehaviorObserver(currentTestExecutionSubject); | |
new BrowserLaunchTestBehaviorObserver(currentTestExecutionSubject); | |
new OwnerTestBehaviorObserver(currentTestExecutionSubject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment