-
-
Notifications
You must be signed in to change notification settings - Fork 546
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I add "post actions" after (null).Should().BeNotNull() is triggered or any other FluentAssertions' extensions ? #906
Comments
Unfortunately, no. There's an |
@cbries could you describe your use case in detail, please? Do you want to register some code to be run for any failed test? Are you sure that test frameworks themselves do not have this kind of callbacks built-in? |
I guess he wants something like: |
Or a generic hook that allows you to run some code before and after the |
@krajek Sure the unittest framework some support that case (somehow). But between the exception and the finalization of the unit test our UI can change completly -- because time is crucial and context changes within the UI are very important and most of our cases (when issues are reported by our customers) depend on the UI state and which toolwindows or editors are open. By the way... how do I know which unit tests failed? Currently I do not know any way to figure out which method failed to create inidivudal screenshot names... By using the callstack?
I have to notice that I am mainly developing VisualStudio 2013/2015/2017 extensions, no web stuff, so our testadapter does start VS-instances, queries for magic dte instances (see https://docs.microsoft.com/en-us/dotnet/api/envdte?redirectedfrom=MSDN&view=visualstudiosdk-2017) and runs our tests. This is the product: https://www.beckhoff.com/TwinCAT-HMI/ The mentioned approach by @eNeRGy164 looks interesting. In that case I could make some fancy setups for the screenshots (e.g. where to store, naming, how many screenshots, probably 10 times after exceptions to see if somethings changes within the ui). The other way looks good enough as well, mentioned by @dennisdoomen, but it should be possible to set these hooks in any unit test individually. Not only during testclass-initialize, it should be possible to set them up at any time. In case my functionality-wish in this issue makes no sense, just tell me... I appreciate any comment. One of our testcases is as follows: [TestMethod]
[TestCategory("Designer")]
[HostType("VSTestHost")]
public void AutomoveCaret()
{
var hmiPrj = CreateProjectAndWaitForDefaultEditor("AutomoveCaret") as TcHmiProjectNode;
var pane = hmiPrj.QueryPane("Desktop.view");
pane.Should().NotBeNull();
var splitPanel = pane.SplitPanel;
splitPanel.Should().NotBeNull();
if (!splitPanel.IsSplitted)
splitPanel.ToggleFullscreen();
WaitFor((out bool b) => b = splitPanel.IsSplitted);
TcHmiVsUi.TimingUtils.Wait1();
var ctrlid = "ViewDesktopBeckhoffLogo";
var textlines = pane.HtmlSource;
textlines.Should().NotBeNull();
textlines.PlaceCaret(ctrlid);
bool resWait = WaitFor((out bool b) => b = hmiPrj.IdentifiersSelected.Count > 0 && hmiPrj.IdentifiersSelected[0].Equals(ctrlid));
resWait.Should().BeTrue("after caret move the identifier should be: " + ctrlid);
splitPanel.ToggleFullscreen();
VsWindow.GetInnerRect().CreateScreenshot(GetMethodName());
} At the end you can see how I do some screenshot of the current state when the test were succesfully. I like to call something like this at any time when |
Alternatively, you can register a central handler by setting the |
@dennisdoomen I said in my PR that this thread was only partially fixed but after a double reading I tend to think this is actually totally fixed. WDYT? |
Yes. They can wrap their call in an |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description
I use fluentassertions in UI tests, works great.
Do you provide any approach for adding callbacks in case FluentAssertions' extensions are triggerd?
For example, when I use the following snippet:
In case resWait is false I like to create a screenshot of the UI.
Can I register callbacks for this case somehow?
Globally would be great to keep the tests clean and simple.
The text was updated successfully, but these errors were encountered: