How to write Unit tests in Flutter using the AAA pattern

  Рет қаралды 308

Runtime Snippets

Runtime Snippets

Күн бұрын

Пікірлер: 13
@abdulbari7246
@abdulbari7246 5 ай бұрын
already excited for the advanced version of unit testing😍
@runtimesnippets
@runtimesnippets 5 ай бұрын
I am glad you liked it!
@runtimesnippets
@runtimesnippets 5 ай бұрын
Working on the next video!
@TylerCodes
@TylerCodes 5 ай бұрын
Hey, this was a really well put together video! Thanks!
@runtimesnippets
@runtimesnippets 5 ай бұрын
Glad you liked it!
@asbahumais655
@asbahumais655 4 ай бұрын
Wonderful!
@runtimesnippets
@runtimesnippets 4 ай бұрын
Glad you like it!
@HistoryBits95
@HistoryBits95 4 ай бұрын
Love it!!
@runtimesnippets
@runtimesnippets 4 ай бұрын
Glad you like it
@lucas.marianno
@lucas.marianno 3 ай бұрын
Great video again! Would you mind further explaining why loops in tests are a bad idea? Following your other video on TDD, I came up with the following test: ```dart test("return 'Fizz' for multiples of 3", () { // arrange const inputs = [3, 6, 9, 12, 33, 66, 99]; // act for (int input in inputs) { final result = solver.execute(input); // assert expect(result, 'Fizz'); } }); ``` Should I divide it into multiple tests for each input? Wouldn't that be a lot more verbose? What is the correct way of thoroughly testing a functionality? Thanks in advance, you got a new subscriber!
@runtimesnippets
@runtimesnippets 3 ай бұрын
1."Why are loops a bad idea in unit tests?" Because 1. loops go against readability and conciseness. 2. The flutter test suite will only give you one output per unit test. So let's say, if your unit test had 7 inputs and one of them was wrong, the entire test will fail. Which is not very descriptive, and doesn't provide you with the right feedback. We also won't be able to know on which iteration the expect method failed. We will have to debug this ourselves. 2. "Should I divide it into multiple tests for each input?" Absolutely! 3. "Wouldn't that be a lot more verbose?" Remember the rule from the TDD video: "Write specific test cases that make your code generic" Meaning: The more specific test cases you have, the more general your code will become in handling different inputs. So it doesn't matter the number of tests you have. One input = One output, and there should be a single test case for that. 4. "What is the correct way of thoroughly testing a functionality?" To thoroughly test a feature, you should identify different edge cases that will break the feature, and then test your code through those inputs. For example, in your method, maybe a multiple of 5 or a multiple of both 3 & 5, might break your feature, so I would test your code with those inputs as well. But be cautious, don't write test cases that keep on testing the same behavior. For example, writing a test case for 3, then 6, then 9, then 12 will keep testing the same behavior of the feature. Once a behavior has been verified, go for different inputs that will test some other part of the method, like 5 or maybe 15. Have any other questions? I would love to answer :)
@lucas.marianno
@lucas.marianno 3 ай бұрын
@@runtimesnippets Got it. Thank you! Cheers from 🇧🇷
@runtimesnippets
@runtimesnippets 3 ай бұрын
@@lucas.marianno you’re welcome!
Test-Driven Development // Fun TDD Introduction with JavaScript
12:55
Одну кружечку 😂❤️
00:12
Денис Кукояка
Рет қаралды 3,1 МЛН
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 8 МЛН
Automate your Testing on Devices with Flutter Integration Testing
20:33
Flutter Explained
Рет қаралды 50 М.
Refactoring a React component - Design Patterns
15:19
Cosden Solutions
Рет қаралды 100 М.
Cody: the AI assistant that actually knows your codebase
10:07
Aaron Francis
Рет қаралды 21 М.
Java Unit Testing with JUnit - Tutorial - How to Create And Use Unit Tests
21:35
Flutter Integration Testing Tutorial For Beginners - Practical Guide
17:06
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 293 М.
The ONLY REASON To Unit Test
8:26
Theo - t3․gg
Рет қаралды 85 М.
Cleaner Code: 3 Ways You Can Write Cleaner Code
7:41
Coding with Lewis
Рет қаралды 95 М.
Одну кружечку 😂❤️
00:12
Денис Кукояка
Рет қаралды 3,1 МЛН