Testing components that uses DevExpress components #370
egil
started this conversation in
Show and tell
Replies: 1 comment 4 replies
-
@egil this is a great set of helpers - I was wondering if you knew of a way to just find all elements (not giving a css selector) with a certain text content? Something similar to this:
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Testing components that uses DevExpress components seems to work quite well. Be aware that, when you write these tests, don't waste time writing tests that tests DevExpress' components. Write your tests such that you primarily target your own code, and don't waste assertions on DevExpress' output, unless you need to.
The recording of how this came to be will be available on YouTube at https://youtu.be/dh_eCrHxnvs from 2021/04/13. Until then, you can watch the recording on twitch.tv/egilhansen, as long as it is archived there
Here is an example that tests the following
DataGrid.razor
component:And here is the necessary code to test it:
The code above shows two different tests that verifies the same thing. The difference between the two is that the first triggers the various events through the event handlers in the DevExpress component which then calls DataGrid components event handlers, the ones we/you write.
The second, on the other hand, with the help of the
InternaVisibleToAttribute
added to the production code project, just invokes the event handler methods directly, completely taking the DevExpress component out of the test. This does have the advantage of being less dependent on how the DevExpress component works, but it skips on testing that the right properties/parameters has been set on the DevExpress component.Note the common set up logic in the tests constructor. With the component under test in this example, that was the only thing we needed to do, to make the test run without a problem.
The following helper extensions makes it easier to get at the right bits of markup rendered by DevExpress:
When testing any component library, your own or others, it is a really good idea to wrap common tasks such as "find a button the text" in extension methods that you can reuse across your tests. Its especially important when your tests are relying on a 3rd party library that might change the markup they produce, which could cause all your tests that rely in it to fail. If you have a set of common methods that handles the markup, then you just need to update one thing and all your tests goes green again.
Beta Was this translation helpful? Give feedback.
All reactions