Unexpected error in unit test with Windows Workflow Foundation (WF

A

Armin Galliker

Hi

I've got an unexpected error in a unit test. I want to test a activity from
Windows Workflow Foundation (WF).

First, I executed the test outside of the activity just in the test-init
method. In this case all works fine:

[TestInitialize()]
public void TestInitialize() {
Assert.IsFalse(true); // test should always fail
}

--> Result in the Test-Result window is as expected: Failed. Assert.IsFalse
failed.


Subsequently, I tried to do the same test in the event handler of my
workflow activity:

[TestInitialize()]
public void MatchingTestBaseInitialize() {

workflowRuntime = new WorkflowRuntime();
workflowRuntime.WorkflowCompleted += delegate(object
sender,WorkflowCompletedEventArgs e) {
Assert.IsFalse(true)
waitHandle.Set();
};

// other event handlers
}

--> Result in the Test-Result window is NOT as expected: Passed.

I stepped through the code:
- at the assertion Assert.IsFalse(true) I've got an exception
(AssertFailedException was unhandled by user code)
- after a waitHandle timeout in my activity expired the test ends and
because there is no other assertion the test passes


Why does this happen? I expected the same result as in the first case...
Should I handle the AssertFailedException by myself even though I didn't
handled it in the first case?
 
C

Ciaran O''Donnell

This is becuase the unit test framework catches these exceptions to figure
out if the test works or fails. When this delegate runs, the testing
framework didnt call the function and therefore cant catch the exceptions.
You need to devise a test that calls the delegate so the test framework can
catch the exception.
 
A

Armin Galliker

You need to devise a test that calls the delegate so the test framework can
catch the exception.

Ok... I would appreciate any help to solve this problem...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top