Тёмный

How To Use TDD For UI Design 

Continuous Delivery
Подписаться 202 тыс.
Просмотров 16 тыс.
50% 1

There are places in the code that make TDD more difficult than others, one of those places is the user interface. People see TDD for UI as a particular problem. The best answer for this is to cheat in a way that makes our testing easier. We can use test driven development to inform our design choices in the user interface to achieve that.
In this episode, Dave Farley author of the books “Continuous Delivery” and “Modern Software Engineering” and long time TDD practitioner, explores testing at the edges of the system
with examples based on testing UI code as part of a TDD approach.
-
⭐ PATREON:
Join the Continuous Delivery community and access extra perks & content! ➡️ bit.ly/ContinuousDeliveryPatreon
-
👕 T-SHIRTS:
A fan of the T-shirts I wear in my videos? Grab your own, at reduced prices EXCLUSIVE TO CONTINUOUS DELIVERY FOLLOWERS! Get money off the already reasonably priced t-shirts!
🔗 Check out their collection HERE: ➡️ bit.ly/3vTkWy3
🚨 DON'T FORGET TO USE THIS DISCOUNT CODE: ContinuousDelivery
-
🖇 LINKS:
Growing Object Oriented Software Guided by Tests, By Nat Price & Steve Freeman ➡️ amzn.to/2Lt3jho
Test Driven Development: By Example (The Addison-Wesley Signature Series), Kent Beck ➡️ amzn.to/2NcqgGh
-
BOOKS:
📖 Dave’s NEW BOOK "Modern Software Engineering" is available as paperback, or kindle here ➡️ amzn.to/3DwdwT3
and NOW as an AUDIOBOOK available on iTunes, Amazon and Audible.
📖 The original, award-winning "Continuous Delivery" book by Dave Farley and Jez Humble ➡️ amzn.to/2WxRYmx
📖 "Continuous Delivery Pipelines" by Dave Farley
Paperback ➡️ amzn.to/3gIULlA
ebook version ➡️ leanpub.com/cd-pipelines
NOTE: If you click on one of the Amazon Affiliate links and buy the book, Continuous Delivery Ltd. will get a small fee for the recommendation with NO increase in cost to you.
-
CHANNEL SPONSORS:
Equal Experts is a product software development consultancy with a network of over 1,000 experienced technology consultants globally. They increase the pace of innovation by using modern software engineering practices that embrace Continuous Delivery, Security, and Operability from the outset ➡️ bit.ly/3ASy8n0
TransFICC provides low-latency connectivity, automated trading workflows and e-trading systems for Fixed Income and Derivatives. TransFICC resolves the issue of market fragmentation by providing banks and asset managers with a unified low-latency, robust and scalable API, which provides connectivity to multiple trading venues while supporting numerous complex workflows across asset classes such as Rates and Credit Bonds, Repos, Mortgage-Backed Securities and Interest Rate Swaps ➡️ transficc.com
#softwareengineer #uidesign

Наука

Опубликовано:

 

31 май 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 96   
@francis_n
@francis_n 2 месяца назад
I get the impression Dave is not much talking about Frontend development but TDDing around a UI. Correct me if I'm wrong. As a frontend developer actually BUILDING UIs in React and testing with Jest/React Testing Library (RTL), I often get into debates with my co-workers who don't believe TDD can be employed when building UIs. We tend to do the exciting thing first which is building the UI then testing afterwards using RTL to simulate the DOM and user interactions, but all this can be TDD'd. To TDD a UI, it's best to stop thinking about the UI as a visual thing (even though it is), but a behavioural thing. So forget about CSS and layout and test what happens when your user interacts with it. How does the UI change in response? What other parts of the system or 3rd party code does it invoke? Does it validate user input correctly? Treat the UI like a function: It has an input (props to the React component or an interaction e.g. button click or input change) and then it has a predictable output (a callback function [mockable] or a DOM element updates). With the inputs and desired outputs (behaviour) known, one can practice writing a failing test: Using a selector to select a DOM element (a button), perform an action (a click) and assert an output behaviour (a DOM element updated with text). Then implement the simplest UI code to get it to work, run the test again to see it go green, and then refactor the UI logic and test. Rinse and repeat. At this stage you're implementing UI business logic and once the test suite is done you can go and add styling and layout afterwards. These should not affect any of your tests because you're not testing pixels and colours and font sizing. For that you can use any number of visual regression tools or snapshotting (in Jest also). TDD is very do-able when actually writing UI code. Treat the UI as behaviour instead of art work. I find the UI code I TDD becomes more modular, leaner and easier to test, and no longer need to hack it to test weird edge cases.
@dinesee1984
@dinesee1984 2 месяца назад
Yeach but are you really testing your business logic here or react itself? You should better write unit tests that check if validation is working correctly and that’s it. I mean, you are checking if pressing onClick calls onClick function, this is a clear framework testing. I would rather test only function that was called inside onClick handler and assert results. We also had discussion and went this way
@jordanfox3782
@jordanfox3782 2 месяца назад
100% agree this is how I test frontend frameworks as well. I wish more of the people I work with were like you 😢
@jordanfox3782
@jordanfox3782 2 месяца назад
​​@@dinesee1984what you are saying makes sense in the context of the video. But my experience with FE frameworks has always been that what I want to test boils down to some kind of output or event on the DOM. There is no real way around that, since the user interacts with the DOM. Testing anything else is comparatively less relevant than that. Doing that testing equates to quite high level integration testing which is generally very fragile, but somehow, angular/react testing libraries are not fragile at all and extremely dependable compared to e2e tests e.g cypress, testim, selenium, which would also be a valid alternative. Would like to hear your thoughts on that or if that makes sense!?
@dinesee1984
@dinesee1984 2 месяца назад
@@jordanfox3782 You are testing DOM actions, so it means you are literally testing if react-dom library is working. This is already tested and stable released by React team. You must be confident in libraries you are using. But validation you write that is performed while user is typing is completely your code and your logic, browser cannot tell if it works as intended because only you know that. I understand that you are afraid that clicking on input and writing text might fail, but in reality in won’t and I am pretty sure those tests will never be edited because they cannot fail (it can only fail if React releases library with bugs). If you want to see if whole form is working you should use e2e tests and these tests are widely adviced, I use them too. But regards to event listeners and dom rendering, seems pointless to me
@francis_n
@francis_n 2 месяца назад
Hey @@dinesee1984 no, we're not testing React or the framework, we're am testing that UI we built with the framework behaves how we want it to behave. An analogy here may help. Imagine you build a car engine. Of course, you build it out of disparate parts, and you use tools to engineer it. When you test it, you're testing the behaviour and functionality of the engine, not the wires, battery, hydraulics or any of the power tools that were used to build it. You test the intention of the engine; all its inputs and all its outputs. This is the same with building a UI. We're not testing React or the DOM, we KNOW and trust they work, we're testing what we built with it worked as intended. If we build a complex form or wizard of screens with complex rules about when to present or hide information from the user etc, this is behaviour we are interested in. For example, think of all the mission-critical UIs that are out there such as trading, scientific tools, financial, medical software with complex user flows. Of course, we'd test business logic which in an ideal world should be decoupled from UI logic but in scenarios you don't want to lose money, customers or lives due to shuddy UI, we'd ideally test a UI that is does what it should. Of course, to validate such expected behaviour we need to assert that the UI reacted in the way we'd expected to in the way we intended it to. We're not testing the DOM we're testing that WE actually implemented the instructions to make the DOM take its expected form. Again to reiterate my point above, I am not thinking visually despite it being a visual element, I'm thinking behaviourally about what the customer is trying to do with the UI and that too can be built up with a sold set of TDD'd test cases.
@gus-199
@gus-199 2 месяца назад
TDD is 100% applicable to UI engineering. Outside-In TDD is great for that: - start with a failing E2E test that checks UI behavior as a user interacts with it (using a tool such as Cypress) - step down to the level of unit tests to implement component logic - make both tests pass - refactor - add styling to achieve the desired look and feel - move back to the E2E level and start again with another behavior It takes a lot of practice, but it's awesome! I've done it in personal projects and would love to do more of it at work too. Unfortunately, I do not always have the conditions to implement it
@nijolas.wilson
@nijolas.wilson 2 месяца назад
That's the exact process I use for improving untested code bases as well 👍
@bernhardkrickl5197
@bernhardkrickl5197 2 месяца назад
That's fine as long as you end up with only a few E2E tests and many, many unit tests. Because E2E tests are very expensive in multiple ways.
@gus-199
@gus-199 2 месяца назад
​@@bernhardkrickl5197 that's exactly the idea. You use E2E to test what's most important from business and users POV, and use the unit tests to test the rest
@TonyWhitley
@TonyWhitley 2 месяца назад
It works the other way round as well, UI developers can use the Adapter layer with a (drastically) simplified model of the business logic underneath it. Then use whatever tools you like to exercise the UI and test the outcomes in the model.
@DodaGarcia
@DodaGarcia 2 месяца назад
The hexagonal architecture is definitely my favorite model for software engineering exactly because of how it encourages that separation between the elements that "drive" behavior and the behavior proper. One thing I find helpful when thinking of UI is to bypass the idea of buttons, selects and other controls and simply look at UI interactions as one form of expression of user intent. My core code doesn't care if a user expressed their intent to purchase through a button click, an API call or a natural language message saying "complete purchase" - all it cares about is whether the intent was expressed and whether enough information was provided for the intent to be accomplished. I've also found it useful to not underestimate how complex the presentational logic can get, with things such as conditional form steps, A/B tests, etc., and then be careful to not get those concerns mixed up with the more business-relevant concerns in the code. I've learned the hard way how messy the development can get otherwise.
@ric7044
@ric7044 2 месяца назад
Hexagonal Architecture is underrated, and it foreshadowed what Microservices became (sometimes, unbeknownst to the developers creating that code!). Go, Alistair Cockburn :)
@dougbit
@dougbit 2 месяца назад
I'm currently developing software using the MVP (Model View Presenter) pattern to achieve UI testability. The Presenter serves as the adapter layer, similar to Dave Farley's example.
@SirBenJamin_
@SirBenJamin_ 2 месяца назад
From a WPF point of view, what you're describing sounds like the ViewModel. As this object interacts with the UI through command bindings, and input/output through property bindings. So nice and clean for unit testing. The problem with testing UIs though is that the order of operations can not be assumed. So you either have to prevent a user from doing things out of your preferred order, oh be very resilient and not make any assumptions
@robinbennett5994
@robinbennett5994 2 месяца назад
The other problem is that much of a system is just simple skin over a database or ORM - and then most of the bugs lurk in the WPF bindings. However, when you do actually have some complex code to test, it does work really well.
@craigyoung8008
@craigyoung8008 2 месяца назад
It’s conceptually the same as any external component testing. That includes things like data stores, and services developed in-house. 1. Determine what the interface between your code and the external component looks like. 2. Ensure the the code under test interacts with the abstract interface and is not bound to a specific concrete implementation. 3. The concrete implementation used during a test is an appropriate mock allowing the test case to verify it uses the external component correctly. 4. The concrete implementation used in production is the third-party framework / external component.
@thought-provoker
@thought-provoker 2 месяца назад
Thank you for the video. I agree on the approach of considering the user as an interface like any other and testing accordingly. I'm a little disappointed though, because I was looking for an answer to my main challenge: TDD to make sure the user sees what they should be seeing, i.e. CSS. I still have no clue how to TDD that, as that's where the assumption "other people's code works correctly" breaks down. Something as simple as "animation-timeline: scroll(Y)" could be totally fine on one device and cause massively broken usability on another.
@nestord1348
@nestord1348 2 месяца назад
you should take a look at testing-library. It can simulate a dom environment and you can certainly TDD. Its pretty popular
@SzybkiTom
@SzybkiTom 2 месяца назад
Nice shirt! Always looking forward to what you'll come up with.
@StaticFlight
@StaticFlight 2 месяца назад
❤ At long last! I've been waiting for this video! I've been doing this for a while but I'm not a software engineer and no one in my professional circle of engineers has ever mentioned this nor shown any interest when I did. I was hesitant to ask you guys directly. So glad when I saw this video. I confess when I saw the title I was thinking to myself "please say abstract layer please say abstract layer" 😂. I am become released!
@raphaelsilva6773
@raphaelsilva6773 2 месяца назад
I have been using an approach that I invented and works very well to TDD the ui. First I focus on developing the layout, in this moment TDD doesn’t help much and I create a completely static layout. Then, I start thinking about the behaviors of my page, I think about the first one, get the data from a server and renders the person name that comes from the server, I create a test for this that fails, so I change my static layout to make it pass and I continue doing this until my static page is changed to be dynamic and all the behaviors are implemented. Currently I am working with React, so I use Jest as it’s being straightforward to use TDD. What I realized was that for some kind of jobs, like layout creation, the TDD is not helpful and it slows the development, making it very difficult but to implement the logics the TDD is amazing, so I segregated the development in two phases: 1: Implement the static layout (without TDD) and 2: Make the layout dynamic with all behaviors (with TDD)
@AndrewEddie
@AndrewEddie 2 месяца назад
I agree totally with the "words" being spoken, but I think this goes over the head of the average React frontend developer when they have Jest tutorials a many to go off. This really needs a part 2 practical example in React (because it's the most prolific) as many engineers, including myself, benefit from visual examples. The one shown somewhat helpful, but the implementation is fairly outdated compared to modern frameworks (React, Vue et al). It's a hard sell to both the current and next generation.
@Kitsune_Dev
@Kitsune_Dev 2 месяца назад
can you talk about TDD for game development?
@orlovskyconsultinggbr2849
@orlovskyconsultinggbr2849 2 месяца назад
Well its actually easy, you test your code outside of your game engine, and when it times comes you simply plug it it, it can be panful if you don't know exact limitations , but if you have good docu of your engine actually nothing can go wrong.
@nothere.northere
@nothere.northere 2 месяца назад
I've just completed a fun tutorial called "TDD and PONG" with Godot game engine and GUT asset library for testing. Recommended for getting started with TDD and game dev.
@orlovskyconsultinggbr2849
@orlovskyconsultinggbr2849 2 месяца назад
@@nothere.northere TDD is separate from game dev, you can use TDD in game dev, but you must understand what you test is not your game engine object your test the behavior of the game objects, and the behavior should be written as a plugin , yes all game objects should not use as component your behavior classes.
@nothere.northere
@nothere.northere 2 месяца назад
Thanks for the feedback! Well, that TDD tutorial for building a game is fun and found it very nourishing. Recommended to give it a try. [:
@maverickmusic101
@maverickmusic101 2 месяца назад
That is the great question
@joepfohl5259
@joepfohl5259 2 месяца назад
Thank you Dave!!!
@runonce
@runonce 2 месяца назад
I'm no TDD expert but I've been following the concept for some time and I don't see what's so special about using it for UI. Using Jest with JSDOM (which is a lot faster than spinning up an actual browser), you first write a test that queries elements on the screen, you simulate some user interactions, and asserts for outputs/changes inside the DOM. Then you start writing the actual UI code to make the test pass. Am I getting it wrong?
@paulhammond8583
@paulhammond8583 2 месяца назад
No, this is a better way.
@francis_n
@francis_n 2 месяца назад
What described is TDD. You've just written a (failing) test case before the actual implementation and then made it work. Now you just gotta refactor and then rinse and repeat. You're now systematically building the UI code test by test, which produces leaner and potentially cleaner and more testable code. At least thats been my experience.
@paulhammond8583
@paulhammond8583 2 месяца назад
You can TDD through the UI using the method Dave describes in his video, or using tools like Jest with JSDOM. I would argue the JSDOM method is better, because you're more accurately simulating user behaviour, and you're also testing a lot of accessibility related concerns when you combine it with the selectors from RTL. The methods Dave is talking about here in my opinion were good advice before such tooling existed. But that tooling does exist so now there's a better way. @@francis_n
@francis_n
@francis_n 2 месяца назад
@@paulhammond8583 In 100% agreement
@JontyMC
@JontyMC Месяц назад
Most modern UI frameworks do not support this way of doing things (or very limited support). I wish they would because it would make testing a lot simpler. The fact is though, that vuejs/react/angular/etc are all view first frameworks. This is where the app is structured via components defined in the view. To enable the kind of abstraction you propose here requires a view model first approach, where the application structure is defined in javascript. You would need to write vanilla js or not use these frameworks. I think this is the reason why a lot of people in other comments are confused how to actually implement what you are describing.
@gammalgris2497
@gammalgris2497 2 месяца назад
Luckily some environments allow inspection of the UI (i.e. component tree). That makes it easier to make automated GUI tests without the need for 3rd party software. Java has the Robot class which comes with the standard libraries. I prefer to test websites by browser automation via Powershell. But you can do it also without a browser. Currently I'm working on a java based game but I started with lots of manual tests to check the behaviour, layout and thread behaviour (so that GUI events are processed correctly, resulting actions don't block updating the GUI, etc.). I will see how things evolve and to which degree I can automate the tests. Form based GUIs are much more simpler to test and automate. The tools my employer bought for GUI testing always had issues because they would just blindly trigger mouse or key events and the tests hung themselves up when dialogues and other unforeseen stuff popped up. Then I started experimenting on my own without the tools and made my own lightweight tools. The unit testing frameworks are agnostic to what you actually do. And it's just a matter of organisation to keep unit tests and other tests separate , as these take more time to execute.
@danielwilkowski5899
@danielwilkowski5899 2 месяца назад
Hi Dave! Great video as always. I have a quick question for you regarding testing UI. I''m writing a CLI application, which allows users to run JavaScript code but in the browser (kind of like node, but with chrome driver, to access DOM for example). I figured out a way to do that, and I start a http server in the cli app, run the driver, send the code to the browser, and it works. I also have websockets so my CLI tool also makes http requests to the driver. I want to do it TDD the right way. I find myself in a place where my CLI application in some situations needs to act as an http server (to serve content to the driver), and as http client - there are cases where that needs to happen simultaneuously. Now the question is, how do I write tests for that? Obviously, if I had to just write a http server, I would write write a test client, send a request, see a test fail, imlement the server, and the test passes. great. If I had to write a http client, I would do the reverse - I would write a test server, to be hit, and then I'd write the real http client to hit that in tests. That's all great. But what If i need both the server and the client in my application simultaneuously? It would seam that to write a server with TDD I need a client, and to write a client I need a server? How would you start coding that with TDD?
@MunyuShizumi
@MunyuShizumi 2 месяца назад
I'm not sure I understand the core idea or use case, but generally speaking, if you have components A and B which may occasionally depend on each other, you'd fake/mock B in tests for A, and vice versa. If A+B doesn't work, it doesn't always tell you whether A or B is broken, and A being broken should ideally be noticed first by tests written for A, not a convoluted acceptance test that includes A+B+C+etc. If the tests for A did not pick this up, it's more often a sign of those tests being insufficient in scope rather than wider acceptance or E2E tests being the solution. If it's difficult to mock A or B, or if it's difficult to write a test for A without B (or vice versa), there's clear design issues that have led to tight coupling between A and B which will eventually cause issues down the line.
@danielwilkowski5899
@danielwilkowski5899 2 месяца назад
@Continuous Delivery I'm really interested in your opinion.
@MC_DarkMaster
@MC_DarkMaster 2 месяца назад
I like the way of Unit-Testing for Blazor. There's bUnit to test the individual components and it works really great.
@zoranProCode
@zoranProCode 2 месяца назад
Interesting, that’s about vanilla JS, bug how if we use some complex UI framework like react? How to make react components dummy and should we? How to wrap all this with unit tests?
@alexhaigh9575
@alexhaigh9575 2 месяца назад
React Components are just functions that return a Jsx Element, so you can mock them like you would any other function.
@peterruszel5389
@peterruszel5389 2 месяца назад
When I see the words "UI Design" I think of a visual output (i.e. styling by a language like HTML or CSS). There can be logic and functionality written with languages like SCSS. I'm curious how this could be tested.
@br3nto
@br3nto 2 месяца назад
Can you show more examples please? E.g how do you do this in reactive style apps? E.g how do you mock chart libraries that draw to the canvas? What are some common examples that can easily be encapsulated? What are some harder examples?
@sysarcher
@sysarcher 2 месяца назад
Not a UI expert here but I think you don't mock the chart libraries. The data that you provide to the library to draw on the canvas is probably derived from business logic. That business logic's implementation needs to be test driven
@sysarcher
@sysarcher 2 месяца назад
e.g if I'm showing percentiles to a teacher for her students, use TDD to make sure that the business logic+adapter return data in a shape consumable by the plotting library. Also make sure of course that the returned data is correct 😂
@BangsarRia
@BangsarRia Месяц назад
Dave you should have worn your Space Invaders T-shirt for this one (you do have one, don't you?). Mine was stolen at the laundromat in 1980 or I'd send it to you. (Ref @7:56)
@elfnecromancer
@elfnecromancer 2 месяца назад
The general statement that the video makes is correct but some details would warrant further research. Jest is a test runner, not a UI testing framework. You can use it to test anything, say, a library or a backend, even something not written in JS. Cypress and Playwright deserve to be mentioned more than Selenium. Using Selenium these days is pure masochism. It's impossible to talk about UI TDD without considering React, the most used UI framework for new projects. React allows us to compose function calls to create a UI as a function of state, with some side effects. Even though there's a lot of magic happening in the background, everything we write in React is essentially a function. It takes some arguments, optionally fires off some side effects, and returns something, so it should be easy to unit test, right? Well, not quite so. The returns of React functions (components) are used by the framework itself, so they are not in a format that means anything to us. To learn how to understand the returns of those functions and perform assertions on them, we would need to understand the internals of React itself and risk having to update our assertions when the framework refactors its internals in a new release. React used to offer a utility for unit testing (react-shallow-renderer), but support for it has been discontinued because the maintainers think unit tests are useless. The modern approach is to use react-testing-library (aka RTL) which makes React renderer into a mock browser (facilitated by jsdom library). This is a good idea in general but falls short of the mark for two major reasons. First, the most popular test runners among frontend developers, Jest and its clone Vitest, are painfully slow. Coupled with the inherent slowness of fully rendering DOM into a mock browser, the advantage of unit tests over full browser tests is greatly diminished. Second, when a react-testing-library test fails, you get a dump of the HTML in a terminal, which can be horrible for debugging larger chunks of UI, and testing larger chunks of UI is sadly something that react-testing-library promotes as a good practice. My current favourite approach is simply not using react-testing-library and doing TDD with Cypress or Playwright. Starting a browser is no longer that slow, and there's a headless mode for CI (usable locally too if you wish). When tests are done the browser remains open and I can time travel through the test to see what happened. In CI, I can get videos and screenshots of failing tests. Logs are nice and user-friendly and there's no spam of warnings from React because we forgot to wrap an interaction in an act() call. What slowness exists can be reduced by cheating: mocking out the backend and skipping to states we want to test. TL;DR * Jest is not a UI testing framewok * Selenium sucks, use Cypress or Playwright * Traditional unit testing of React is a pain * Better to do TDD with UI acceptance tests
@michaeljuliano8839
@michaeljuliano8839 2 месяца назад
I agree with the approach as stated. I do, however, think that there is a hole from the standpoint of UI design. There is no way to drive your UI design with automated tests in the same way you drive code design with them. That is to say, the arrangement of UI elements is not something that can be cleanly driven by considering how you might test it. It’s a bit outside the scope of what this channel does, but I do think it’s an area worth exploring to the extent that some feedback mechanism is strongly desired to help uncover good UI design in an organic, self-driven way.
@ContinuousDelivery
@ContinuousDelivery 2 месяца назад
I don't think that "UI-design" in the sense that you mean is a good role for TDD, TDD works best when focused on the behaviour on the system, not how pretty it looks, you need other forms of testing to support how it looks.
@brownhorsesoftware3605
@brownhorsesoftware3605 2 месяца назад
​@@ContinuousDelivery In a browser your UI is in service to your backend. On a phone your backend is in service to your UI. On my phone app this makes everything transparent to the user. Run == test. Instead of swapping out the UI to test, I swapped out the backend from network to file system. Startup time including deployment from the IDE is seconds. The cheapest cpu is on phones.
@francis_n
@francis_n 2 месяца назад
@michaeljuliano8839 See my response above as to how I go about TDD when building UIs. Treat the UI as a behavioural system rather than pixels and layout. Test user interaction and assret what should happen when the user interacts with it. With that said, TDD is doable. The actual "UI Design" can be asserted using snapshotting or visual regression tooling which is more an after test.
@michaeljuliano8839
@michaeljuliano8839 2 месяца назад
@@ContinuousDelivery I agree. I think the feedback mechanism for UI design in this sense is something that ought to be discussed, though I do think that discussion falls outside the scope of what you’re trying to do here. I would still be interested if it ever came up in an engineering room discussion.
@BloodEyePact
@BloodEyePact 2 месяца назад
I'm not a big fan of mocking things out like this. There's a trade-off for the speed of feedback vs the confidence in the results, and you want to optimize for speed, but beyond a certain point, it provides so little confidence in the actual product as it would be delivered that it isn't worth the effort, especially once your tests start getting coupled to the parts of the interface (in the architectural sense) your users have no interaction with. If anything, from this, the principles of TDD tell us that reliable systems should have simple user interfaces, and the focus should be on testing the internal components, and optimizing how we test the UI, for example using tabs instead of launching an entire new browser window, interacting with the DOM instead of simulating keystrokes and mouse clicks, and using multiple cores for parallel tests. I use the Go library Biloba which was designed from the ground up with these ideas, and I'm able to execute dozens of cases per second, and this would be way more if I wasn't executing them on a decade-old machine.
@RFalhar
@RFalhar 2 месяца назад
"adapter - a thin, simple layer" I dissagree. My (limited) experience with UI development and attempts at writing fast automated tests make me believe that writing such adapter code often results in levels of complexity almost comparable to the UI framework itself. Especially if rich, UX-friendly, responsive UI is required. Which is why the selenium approach is often seen as cheaper compared to having to basically re-implement a custom UI framework. I think the only real solution would be for UI frameworks to actually start supporting automated testing as first-class citizen. Providing adapters and test fakes that emulate behavior of the real code for testing purposes. But that is not happening, as test automation is seen as annoying or unecessary.
@ContinuousDelivery
@ContinuousDelivery 2 месяца назад
Well, it worked very well for us, for a rich, UX-friendly, responsive, UI.
@electronicXtacy
@electronicXtacy 2 месяца назад
Please do Flutter and Jetpack Compose some justice and check out the way they solved testing. Specifically flutter is easy to use and drives real devices and headless without effort.
@sysarcher
@sysarcher 2 месяца назад
Maybe you're not focusing your testing on business logic but on the UI itself?? That adapter layer is typically just a data-shaping thing that for instance massages data returned from business logic with stuff consumable by UI. Example: a plot showing stock performance. The adapter is responsible for shaping the data in the format consumable by the plotting lib. Business logic that returns stocks performance can be TDD'd
@RFalhar
@RFalhar 2 месяца назад
@@sysarcher So you are saying it isn't necessary to test UI logic? Well you are wrong then! How would it make sense not to test important part of user-facing application?
@egalanos
@egalanos 2 месяца назад
Doesn't a web test framework like Playwright effectively give you that without introducing your own adapter layer?
@stephendgreen1502
@stephendgreen1502 2 месяца назад
Maybe this is a weakness in the full stack development concept. If UI specialists write backend code, maybe they are less likely to use TDD or even be aware of the importance of unit tests.
@gus-199
@gus-199 2 месяца назад
It's usually the other way around. Full-stack devs are generally people who do more backend stuff and have some knowledge of React (for example) that they can rely on to implement simple stuff. Harmless in small scale, but can wreck the whole UI architecture if left unchecked without a UI specialist. The hard thing these days is convincing companies they need UI specialists. They hire for UI but expect to do backend too, therefore full-stack. UI engineering is not very respected.
@gus-199
@gus-199 2 месяца назад
There's an interesting article about this. Search for the ongoing defense of frontend development as a full time job (or something like this)
@PieterWigboldus
@PieterWigboldus 2 месяца назад
UI is a side effect, so hard to test
@tomwaitforitmy
@tomwaitforitmy Месяц назад
I’m a bit disappointed from the video. The whole point of TDD is writing the tests first, before you know what UI you will have. I understand the mentioned concept, but I don’t understand how to get the humble object with TDD. All in the video sounds to me like writing tests after you have the UI. My usual struggle with TDD and UI is, that I need to visualise the UI to see what I want. Does it fit nicely on the screen? Do I need to pop up an extra dialog, because that tiny edge case feature that most users don’t care about takes a majority of the screen? Can you read everything nicely? Do I need a button to do back or revert things? Does the layout look nice and intuitive? Do I need to change the order of input fields? All these questions I struggle to write tests for. Especially, before I know roughly the final design.
@orlovskyconsultinggbr2849
@orlovskyconsultinggbr2849 2 месяца назад
Testing UI? hm i have doubts that it can be done easily, sure there exist tools like SmartBear Test complete and Microfocus UFT, but really what people testing through UI? Right , business logic! So really people be professional , in my opinion testing strategy should be to test first business logic separately from UI. Now there maybe other professionals which would say it already hard work to test stuff and you suggest even more refactoring work for decouple from the direct access from UI ? Yes that's what i propose, your business logic is what makes money for your company, if you make it "hostage" to UI by hard coupling it , as some UI vendors propose , you make yourself dependent from them and rely on theirs "mercy". Of course It depends on your case, but decoupling is the way out of this cage and running UI tests is not fun, they breaking way to often.
@francis_n
@francis_n 2 месяца назад
I would argue one should/could still test their UI. You can have the best tested and coded business logic but if you're UI doesn't work properly because someone has not written good automated tests to test assert correct UI behaviour e.g. validation, correct flow etc etc, then your customers wont stay very long using your amazing business logic
@orlovskyconsultinggbr2849
@orlovskyconsultinggbr2849 2 месяца назад
@@francis_n Yes it make sense, but look at the business side of things, if a particular UI vendor don't provide tools for testing of UI, what will happen ? Your company put somebody at work which would write brittle tests, tests which would work only at one version of UI and break if UI vendor change stuff. So normally what good companies doing , they have the "toolbox" for UI testing, but theirs business logic is decoupled , devs write test only for the business logic, and testers write tests for UI and if for some strange reason UI get defunct , no problem take another ui write new ui tests ,but for the business logic nothing will change.
@orlovskyconsultinggbr2849
@orlovskyconsultinggbr2849 2 месяца назад
@@francis_n Another point, if your app business logic coupled with UI, you loose flexibility and agility for change, i dont know like think of the future, next big thing implant chips, AR , people buy bigger screens and or use projector or even digital watches.
@francis_n
@francis_n 2 месяца назад
@@orlovskyconsultinggbr2849 Yes, I agree with you. I guess I am coming at this from the point of view of an actual FE UI developer writing code in React. React, like any technology, won't be around forever but is a pretty stable industry standard UI framework at the moment so not going anywhere anytime soon. The UI code I write is more likely going to change due to business requirements changing than it's vendor (Facebook) deciding to trash it anytime soon. The UI can be tested very well and is not meant to be thrown away. Of course, the business logic should always be decoupled from UI logic, so change in one won't affect the other.
@francis_n
@francis_n 2 месяца назад
Also, I gave a longer take above. I feel like Dave is not actually talking building UIs but rather TDDing business logic that is going to be consumed by a UI, so testing around the edges of the system. That's fine. My gripe amongst my peers (UI developers) is the notion that UI code cannot be built using TDD.
@forlua9211
@forlua9211 2 месяца назад
IMO, TDD doesn't work well for all types of jobs such as 1) In Some works where the outputs can not be (exactly) predetermined e.g. research works. 2) In some works that require code -> test -> adjust loop for the program development e.g. some parts of UI or game developments. I think certain types/parts of UI developments could work very well with the TDD, but if some parts, writing the code first then testing later work better, I don't see the reason why we should insist on using TDD on those parts. Sometimes, people forget the whole point of the software engineering and use the TDD just for the sake of using the TDD. The fact is not in all types of applications you can finish the design before you write the tests, some works require your hands to get dirty, test, observe, adjust, and repeat to work more effectively
@ContinuousDelivery
@ContinuousDelivery 2 месяца назад
I don't agree with those as problem areas, I think TDD works better in both of those cases than the alternatives, but it does depend a lot on your approach to TDD, and more importantly to it's use in guiding design.
@forlua9211
@forlua9211 2 месяца назад
​@@ContinuousDelivery I don't agree with you I am a doing some kind of research work and many works of mine, the results cannot predetermined. I know what I expect from my code but it is not clear enough to write the test (and it cannot be clear because it is a research, it is a "let's see what we get" type of work). In the real world, not all the works you can predetermine the exact values of the inputs or the outputs. Since the input and the output are basic requirements for the TDD, any work that the inputs or the outputs are not well-defined, hacking the code for doing the TDD sounds counter-intuitive to me.
@forlua9211
@forlua9211 2 месяца назад
​@@ContinuousDelivery Don't you think any work that requires complex implementation of the TDD is actually an anti-pattern for using the TDD?
@johnridout6540
@johnridout6540 2 месяца назад
With respect to UI development. When I explore different possible implementations I don't write tests, because they rapidly become obsolete, but once I've settled on an approach then I write tests for that approach.
@forlua9211
@forlua9211 2 месяца назад
@@johnridout6540That is what I was talking about. There are certain types of works where you cannot precisely define the program output. One has to experiment with the code until the desirable output is reached. Using TDD, in this case, can potentially double the workload where one has to update the source code with the tests in each design/experimental iteration. Inputs and outputs of the program are the basic requirements of the TDD. If they cannot be precisely predefined, I would accept the fact that the nature of the work doesn't fit the TDD. Not all the programs in this world you can finish the design on paper before you write code, some works require your hands to get dirty. It's like doing music, one could finish composing the song on paper without touching any musical instrument. But this way of composing the music cannot be as effective as playing the musical instrument together while writing song.
@MJSmithGroup
@MJSmithGroup 2 месяца назад
TDD for UI? Don't release anything until 99.99% of users can pass your tests. EZPZ.
@kahnfatman
@kahnfatman 2 месяца назад
When the desired outcome is not understood- no testing is beneficial. For coding is more of an art than an engineering. Until we make coding as boring as laying bricks, whatever DD is never a silver bullet, but rather GOLDEN COWs to which the priests (book sellers/authors/distributors/RU-vidrs) thus proclaim „This is our god, who brought us out of Egypt! Bow down and worship! Dance, drink and do all kinds of org***s“
@rursus8354
@rursus8354 2 месяца назад
The case was not made: just dismissing the function of an external library function that something that you should trust, is a bad rationalization. Perhaps they didn't make the test that they "should", and you cannot blame your own misunderstandings on the foreign library.
@paulhammond8583
@paulhammond8583 2 месяца назад
Hi Dave. I'm a big fan of yours, but I think I can show you a better way to do TDD on the front end. I reached out to you via a private message on LinkedIn. If you'd be interested at all in discussing this with me, please take a look and see what you think.
Далее
USER STORIES Shouldn’t Be TOO BIG
15:27
Просмотров 19 тыс.
Test Driven DESIGN - Step by Step
25:46
Просмотров 19 тыс.
Я Не Спал 100 Часов!
00:39
Просмотров 40 тыс.
Where Agile Gets It Wrong
19:22
Просмотров 29 тыс.
I’ve Found Something BETTER Than Pull Requests...
23:36
Why I Quit the Scrum Alliance
7:58
Просмотров 4,4 тыс.
Why Software Estimations Are Always Wrong
14:22
Просмотров 47 тыс.
Testing WITHOUT Mocks or Interfaces!
12:27
Просмотров 24 тыс.
Interview with a Senior C# Developer
10:56
Просмотров 593 тыс.
The WORST Way to Develop Software
15:16
Просмотров 20 тыс.
TDD or BDD When It Comes To Automated Testing?
12:45
Просмотров 20 тыс.
Software Architecture Tips I WISH I Knew Sooner
18:04
Amateur vs Pro UI Design | with examples
20:46
Просмотров 36 тыс.
AMD больше не конкурент для Intel
0:57
🤔Почему Samsung ПОМОГАЕТ Apple?
0:48
Просмотров 462 тыс.