Thanks a lot for this suggestion but unfortunately it isn't 100%
reliable - sometimes it works and sometimes it is not (like my try-
catch block). I'll try to dig into my tests code and understand why it
is happening.

BR
Marcin

On 14 Kwi, 18:00, Graham Hay <[email protected]> wrote:
> Hmm, that's a bit tricky. There's a few solutions but none of them are very
> nice.
>
> What you really want is to be able to provide your own assertion context,
> or at least change the behaviour when a failure is reported. Unfortunately
> none of that code is extensible, as far as I can tell.
>
> That's an area we can look to improve, but for now you might have to cobble
> something together yourself. How about something like this?
>
>         [Test]
>         public void Multiple_asserts_with_screenshot()
>         {
>             var success = false;
>
>             WithScreenshot(() => Assert.IsTrue(false), ref success);
>             WithScreenshot(() => Assert.AreEqual(1, 2), ref success);
>
>             Assert.IsTrue(success);
>         }
>
>         private void WithScreenshot(Action action, ref bool success)
>         {
>             try
>             {
>                 action();
>             }
>             catch (AssertionFailureException)
>             {
>                 var bitmap = Capture.Screenshot();
>
> TestContext.CurrentContext.LogWriter.Default.EmbedImage(null, bitmap);
>                 success = false;
>             }
>         }
>
> On 13 April 2012 20:29, manx <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi
>
> > Basically I'd like to make a screenshot of active window whenever
> > assertion fails (at least for now). As I mentioned before I perform
> > tests within multiple assertion block so I don't want to wait for
> > entire test completion to make this screenshot. Also built-in
> > screenshot mechanism is not satisfying for me since I didn't see
> > triggers different from test finish, test failure etc.
>
> > I tried to put whole test in try - catch block and catch
> > AssertionException but it doesn't work in every case and I wasn't able
> > to figure out why.
>
> > On 13 Kwi, 18:13, Graham Hay <[email protected]> wrote:
> > > Exactly what behaviour are you looking for? Do you want to perform the
> > > action when the assert fails, or can you wait until the test has
> > completed?
>
> > > On 13 April 2012 10:24, manx <[email protected]> wrote:
>
> > > > Hi
>
> > > > I need to write own custom attribute to decorate test method which
> > > > will allow me to perform any action when assertion fails. My tests are
> > > > already with [MultipleAsserts] attribute so this action cannot be
> > > > triggered when test fails but when single assertion fails.
>
> > > > I appreciate any suggestions
> > > > M.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "MbUnit.User" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected].
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/mbunituser?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "MbUnit.User" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/mbunituser?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mbunituser?hl=en.

Reply via email to