Unit Testing a SwiftUI application in Xcode | Advanced Learning #17

  Рет қаралды 35,895

Swiftful Thinking

Swiftful Thinking

2 жыл бұрын

Being able to write good Unit Tests is one of the most important skills to have when when applying for iOS jobs. In this video we will learn how to add tests to our Xcode project and review all of the different types of tests that we can use in different situations.
By the end of this video, you will be a testing expert! We are covering a broad range of tests, including testing Combine code and asynchronous tests!
"We don't write tests for today, but for tomorrow."
By having written good tests in a project, we can confidently push our app to users without having to worry if something accidentally broke our code. Writing great tests will help you avoid thousands of bugs in your project.
Hacking With Swift textbook: www.hackingwithswift.com/stor...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-thinking.com
DISCORD: / discord
GITHUB: github.com/SwiftfulThinking/
SAY THANKS: www.buymeacoffee.com/nicksarno

Пікірлер: 74
@chrisrockscode1202
@chrisrockscode1202 2 жыл бұрын
Are you kidding me! I swear this is the first decent unit testing video I’ve ever seen and I’m only like 15 min in! You got me hooked! You are going to make waves in the community!
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thanks Chris!! Glad you enjoyed the vid
@lincolndickerson1293
@lincolndickerson1293 2 жыл бұрын
First, fantastic coverage of this topic. I needed a refresher for my current assignment this exceeded my expectations. A couple things to add. 1) Our test classes are just that and it is very useful at times to write helper functions within the test class that are not prepended with test_. Maybe you have a scenario that you want to test your data array with all evens or all odds in many tests. Creating funcs to do setup the data outside the setup/teardown funcs can be super handy. 2) Creating automated tests for you code always saves time: A) you are going to test the code anyway one or another if you are a decent software engineer. By making it an automated test you get to use it 10s of thousands of times or more. Your “one time” test code now does not get thrown away. B) When you write the tests you are in a different mindset. You naturally think of checking all the edge cases and rarely say, “I thought I tested that”. C) TDD with paired programming is the most cost effective way to develop software and is also the hardest concept to sell to those with the money. Come up with a good way of selling the concept. D) Developers should write all the fundemental tests. The testing team, if you are fortunate enough to have them, should be writing far more advanced tests. For instance the developr should write download tests like there are here. The testing team should be creating partially corrupt data tests, slow and hyperfast download speed… Testers are not for finding developer fundemental mistakes 3) No need to apologize for the length of the video. KZfaq gave me this handy pause button, I take as many breaks as needed to get through the whole thing. 😉 On to UI Testing review next. Thanks again.
@tanvirgeek
@tanvirgeek 2 жыл бұрын
I worked with apple. I think you are the best SwiftUI KZfaqr. :)
@superrickhardy5032
@superrickhardy5032 Жыл бұрын
Found your videos yesterday. You are really saving me a lot of time. Great material. Thanks!
@era_i_ser7967
@era_i_ser7967 2 жыл бұрын
This is the part that I've been looking forward to the most since this series started. always thanks
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
It's getting "real" now lol
@begumyazicialici3372
@begumyazicialici3372 Жыл бұрын
I've never seen a better explanation! Thank you so much for this superb video, which saved me a lot of time:)
@josealjndro
@josealjndro 2 жыл бұрын
Best unit testing video with Swift!
@stanleyejechi1417
@stanleyejechi1417 Жыл бұрын
Awesome! Thank you for the video, Nick
@ronjurincie7760
@ronjurincie7760 2 жыл бұрын
Such an informative video. Super helpful. I feel very good about Xcode Unit Tests now. FINALLY!
@bbongrip
@bbongrip 2 жыл бұрын
Been waiting for this video. Really good man. One of my favorite Swift videos of all time.
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
I was hoping someone would like this one! Thanks for the comment 🥲
@Srijonlucky0111
@Srijonlucky0111 Жыл бұрын
It's awesome! I am gonna add new skill in my bucket. Thanks for this awesome explanation. I always find your explanation a lot easier to understand. Thanks again.
@user-eg7ep8db8j
@user-eg7ep8db8j 2 жыл бұрын
This is amazing video!! This is definitely my favorite swift learning channel~!!
@candylover2456
@candylover2456 2 жыл бұрын
Amazing as always. Thanks so much Nick :)
@amith2947
@amith2947 2 жыл бұрын
bro, I was waiting for this video for a long time. thank you and never feel bad just because of the video length. keep grinding
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Amith! Haven't seen you lately. Glad you're still watching 😜
@amith2947
@amith2947 2 жыл бұрын
@@SwiftfulThinking mate, I will never miss your videos!!! Everyone, please subscribe to this channel, I'm begging you. he is an amazing teacher.
@puneethkamath3975
@puneethkamath3975 2 жыл бұрын
Excellent video. thank you!
@obsessed92
@obsessed92 Жыл бұрын
Great video, well explained. Thank you.
@kyunghwankim1269
@kyunghwankim1269 2 жыл бұрын
Amazing! Thank you very much.
@user-qw5kp9it6m
@user-qw5kp9it6m Жыл бұрын
Great explanation! Thank you for your effort! Would be great to have one about TDD :)
@bingl172
@bingl172 10 ай бұрын
Amazing tutorial!!! thanks nick
@suryakantsharma6761
@suryakantsharma6761 Жыл бұрын
Great explanation! Thank you for your effort! Would love to have with TDD.
@ShubhamKumar-rs5vc
@ShubhamKumar-rs5vc 2 жыл бұрын
Your channel is just awesome, I started Swift 2 weeks ago, and Now I am great at It.
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
This is exactly why I made the channel. I’m happy to hear it! 🚀🚀🚀
@AX100G
@AX100G Жыл бұрын
Nice video! Just a quick FYI XCTest will create a new instance of your XCTestCase subclass for every single test in the class. -State wont be shared amongst your tests unless they write to a database, or are static (or similar)
@caseywest4695
@caseywest4695 Жыл бұрын
Amazing video. I've been coding for 7 years and manage a team of 10...looking to implement unit testing for my team. Going to have them all watch this as a start :)
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
That’s awesome to hear! Thanks for watching Casey 🍻
@iliasmerigh9650
@iliasmerigh9650 7 ай бұрын
Excellent explanations
@NaNi-bl5pc
@NaNi-bl5pc 4 ай бұрын
A MUST LOOK VIDEO!
@aleksandertesenkov1421
@aleksandertesenkov1421 7 ай бұрын
Excellent video. It’s very educational. Please keep going.
@kdtechniquesofficial6153
@kdtechniquesofficial6153 Жыл бұрын
I didn’t even know how to do this until now. Thanks angel.❤
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
KD ON FIRE
@hyggeboi
@hyggeboi Жыл бұрын
awesome, thanks
@Pepe_the_raver
@Pepe_the_raver 10 ай бұрын
I'm so excited for having found this tutorial, it looks really promising and I can't wait to start coding & learning!
@SwiftfulThinking
@SwiftfulThinking 10 ай бұрын
Hope you enjoy it!
@Pepe_the_raver
@Pepe_the_raver 9 ай бұрын
@@SwiftfulThinking Finished it, now I can say I finally feel comfortable facing the challenge of creating tests for my apps. Thanks a lot for this priceless lesson.
@Art-is-craft
@Art-is-craft 8 ай бұрын
The real power of unit tests is that they can be used to actually design data and to also help structure a function. They are an extremely powerful tool to allow you to write templates.
@maartenborsje
@maartenborsje Жыл бұрын
It would be really nice if you could make a video about unit testing core data. For example the video you made for creating an app with core data with multiple entities.
@alwaysrookie583
@alwaysrookie583 Жыл бұрын
Thank you man
@jarodpaulson9439
@jarodpaulson9439 2 жыл бұрын
Hi Nick, thanks for yet another amazing video. I was hoping you could elaborate on why you created a local array for certain tests (ex. the ...shouldSaveItem( ) test) instead of just using the view model's dataArray property?
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Great question and it goes back to.. why are we writing these tests anyway? Here, we are testing that the ViewModel is working correctly... so we need something to compare the ViewModel's data against. While writing the test, we know that the local array is correct. Therefore, if the ViewModel's data matches the local array, then it must be correct too
@lofistudywithsayasan912
@lofistudywithsayasan912 7 ай бұрын
Love you my teacher ❤
@mrslana3049
@mrslana3049 2 жыл бұрын
The best in swift
@Voeris
@Voeris Жыл бұрын
You're a terrific tutor Nick, thank you very much for your work! Just a quick question: why use a separate itemsArray collection in saveItem_shouldSaveItem() (line 218)? Isn't it enough to just use the dataArray property belonging to the vm?
@SwiftDeveloperWorld
@SwiftDeveloperWorld Ай бұрын
Dear nick, please provide something related to T.D.D too, thank you
@nurlankalybekov7336
@nurlankalybekov7336 3 күн бұрын
Even a lazy programmer would watch this. Means, it is easy to understand
@filipp7236
@filipp7236 19 күн бұрын
The first half of the video made sense to me. The second half requires a few more viewings.
@TheSpiralnotizblock
@TheSpiralnotizblock 2 жыл бұрын
good shortcut for testing is cmd + u
@mahmoudzinji5672
@mahmoudzinji5672 Жыл бұрын
Can you please share if yu have a tutorial that tests the Networking layer of an application
@rrr7073
@rrr7073 2 жыл бұрын
It was a very informative video. It helped me a lot while writing unit test. I want to ask something. I used firebase in my application where I want to write unit test and I need to create an instance for firestore.firestore. how can i write this?
@alexl2512
@alexl2512 Жыл бұрын
Incredible explanation. 🎉🎉🎉 Assume we have a dataService class reading and writing data to back end. This dataService would be used in multiple view model. The app should initialize the dataService after launching and stores it into the environment. Then all the views can get access to it and inject it into the view model of their own. Am I right about this? Is there a better way to organize the code?
@tamasterjek7520
@tamasterjek7520 2 жыл бұрын
Great series. What do you think about MockingBird library for mocks? With java background writing your own mocks seems cumbersome...
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
I've never used that library, but it does Iook like a good option. I'd prefer to have as few external dependencies in an app as possible, so I usually just make the mocks myself.
@degisner
@degisner 2 жыл бұрын
Cool, thanks man! Please consider create a icloudkit video 🙏
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
A CloudKit video? How about several? 😂 They're coming soon !
@degisner
@degisner 2 жыл бұрын
@@SwiftfulThinking would be cool! Thank you for your content. I learned a lot!
@user-gw5nk3vt7w
@user-gw5nk3vt7w 7 ай бұрын
How do write unit tests for vars or funcs in the original code that are marked private? I did not find a way other than remove the "private" while testing. Any ideas? Did I miss something in the video? Great video by the way, the whole series.
@SwiftfulThinking
@SwiftfulThinking 7 ай бұрын
You generally do not need to write tests for the private functions. Since they are private, then they are only being accessed from within the class. Therefore the unit tests for your public functions would already be incorporating and calling the private methods.
@sudhakard5273
@sudhakard5273 5 ай бұрын
Kindly make a video on writing unit tests for API calls also. Or Can anyone suggest me a video link on this if you know
@nsr-rpaevolver1584
@nsr-rpaevolver1584 2 жыл бұрын
Hi Bro, Just Started watching...now partially finished
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Haha 😎
@robertmylne2942
@robertmylne2942 Жыл бұрын
How would you include String extensions though? I am getting an error when trying to include them Value of type 'String' has no member 'myfunction'
@robertmylne2942
@robertmylne2942 Жыл бұрын
For anyone wondering, I worked it out. You need to select "target membership" from the right hand menu of the file you want to include.
@SwiftDeveloperWorld
@SwiftDeveloperWorld Ай бұрын
is it right to specify the name of the test function on that much long as we can? can we summarise it only in a comment?
@SwiftfulThinking
@SwiftfulThinking Ай бұрын
Imagine a big project with 100s of test and many other engineers. You want to make sure another engineer looking at your code knows exactly what each function is testing. You can change the structure and documentation as needed, I was just showing a common approach!
@arkemal
@arkemal 9 ай бұрын
Where can I download the starter project? Thanks
@SwiftfulThinking
@SwiftfulThinking 9 ай бұрын
Everything is on GitHub @SwiftfulThinking
@arkemal
@arkemal 9 ай бұрын
Thank you @@SwiftfulThinking
@nsr-rpaevolver1584
@nsr-rpaevolver1584 2 жыл бұрын
Hi bro, can you make a series on VIPER architecture
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Hey, no sorry I'm not a fan of VIPER and it doesn't work very well with SwiftUI. I will be making advanced courses that use a complex MVVM+ architecture, which will get most of the benefits that VIPER would bring to our app anyway.
@toomee4674
@toomee4674 Жыл бұрын
Hi :) If I wrong, please correct me 🙏 52:58 - func test_UnitTestBootcampViewModel_selectedItem_shouldBeSelected_stress() You have created a new variable: var itemsArray: [String] = [ ] - But it seems pointless to me. Here is your code: // When let loopCount: Int = Int.random(in: 1..
UI Testing a SwiftUI application in Xcode | Advanced Learning #18
1:36:58
Swiftful Thinking
Рет қаралды 21 М.
How to use Dependency Injection in SwiftUI | Advanced Learning #16
35:32
Swiftful Thinking
Рет қаралды 27 М.
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,5 МЛН
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
Getting Started with Unit Testing in iOS (Unit Testing Part 1)
8:49
How to use Protocols in Swift | Advanced Learning #15
28:37
Swiftful Thinking
Рет қаралды 15 М.
What's going on with Windows Laptops?
10:30
Marques Brownlee
Рет қаралды 2,7 МЛН
How to implement a Mock in Swift!
8:19
Vincent Pradeilles
Рет қаралды 5 М.
TDD and Unit Testing in iOS | Part 1 Stateless Objects
28:27
Sam Meech-Ward
Рет қаралды 8 М.
Swift Dependency Injection - What is it? What are the benefits?
6:58