Hade0011
Hade0011

Reputation: 111

How to run a method in a unit Test only after a method in my application has finished?

I want to test a value in my unit test. This value is set in a method which is called by a button click in the main application. I'd like to have code like this in the unit test:

after ButtonClick().isFinished{ //insert working code here?
    TestMethod();
}

public void TestMethod(){
    Assert.AreEqual(value, "foo");
}

In the main application there is code like this:

protected void ButtonClick(object sender, EventArgs e){
    value="foo";
}

I don't want to change ButtonClick if possible because I don't want to mingle application code and test code.

P.S. This is my first question on Stackoverflow, so please cut me some slack for my noob ways :)

Upvotes: 0

Views: 254

Answers (1)

Christiaan Nieuwlaat
Christiaan Nieuwlaat

Reputation: 1359

I think you could just invoke the method the following way

[Test]
public void testMe() {
  ButtonClick(this, EventArgs.Empty)
  Assert.AreEqual(value, "foo")
}

Upvotes: 1

Related Questions