Why do we need test case in swift | xctest | unit testing | code coverage

Поделиться
HTML-код
  • Опубликовано: 1 авг 2024
  • What is unit testing in swift or how to write unit test cases in swift has been a question for beginners and sometimes even experienced swift developers, in this ios testing tutorial we will cover in details as to why unit testing is important and how to write unit tests in swift.
    Write test case in swift project to make sure that you have covered all the required use cases of your module, this video also talks about the difference between unit test vs integration test and covers the detail from an interview perspective.
    Given are the chapters covered in this video
    0:00 introduction
    0:49 topics covered in this video
    1:01 what are unit tests and why do we need them?
    1:17 unit testing codecat15 example
    4:20 responsibility of dev
    5:13 types of test cases
    7:03 demo
    7:11 code walkthrough
    8:32 walkthrough of a test class
    10:21 creating a test class
    11:23 how to write a test function
    17:10 run all the tests at once
    17:39 test first approach
    20:12 impact on test cases due to code change
    21:22 test cases are proof that our code works
    21:56 what is code coverage
    24:03 pending work for next session
    24:16 be honest while writing a test case
    Link of decomposition video: • Decomposing Model view...
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ✅ Subscribe to the channel and stay ahead of everyone by following the right way for writing clean code in swift. 🔥🔥🔥🔥🔥
    🔗Click on the link to subscribe: ruclips.net/user/codecat?sub...
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -----------------------------------------------------------------------------------------------------------------------
    📥 Download the source code from
    Github: github.com/codecat15/RUclips-...
    Google Drive: drive.google.com/file/d/1PwLN...
    ----------------------------------------------------------------------------------------------------------------------
    ############################################
    Connect with me on social media
    📧: codecat15@gmail.com
    🐦: / codecat15
    Facebook: / code.cat.792
    Github: github.com/codecat15
    ###########################################
    #whatIsTestCase #unitTestingInSwift #howToWriteTestCaseInSwift

Комментарии • 84

  • @CodeCat15
    @CodeCat15  3 года назад +8

    In this video, we will understand what are test cases and why do we need them along with the difference between unit and integration test case, we will understand the need for a writing unit test case in a project with the help of an example. In the second part of the video where we will learn how to write test cases for an API along with some good practices. If you have any questions on this topic please do ask in the comments and do share the video with your friends and do support the channel by subscribing to it. Happy iCoding.

  • @darshantelang1535
    @darshantelang1535 3 года назад +1

    Excellent intro to Unit Test Cases. I liked mention of Code Coverage and its importance. #CheersToCodeCat15

    • @CodeCat15
      @CodeCat15  3 года назад +2

      Code coverage is something that's ignored by many, and devs feel that just by adding test cases they are doing a good job but then really it all boils down to how much of your code is covered with test, are you performing integration test with happy and failure path scenarios coz just like for every if condition we need an else similarly for every happy path we need a failure path test cases as well.
      I make sure that when I get the PR, the code coverage is more than 70% else I reject that PR, well I do have that automated in my build configurations hehe

  • @pushpender.s
    @pushpender.s 3 года назад +4

    This is called quality content… I have seen few videos of yours from yesterday and i would say it’s great.
    my company is going to change my team and in the new team, I have to write test cases and Jenkins will take screenshots.
    These types of videos has limited audience still you are creating with full of passion so thank you so much.

    • @CodeCat15
      @CodeCat15  3 года назад +1

      Much appreciated! Thank you for your kind words. I am glad this channel and its content are proving to be helpful. I also share some short swift content on my instagram account (@codecat15) so do check that out as well :)

    • @pushpender.s
      @pushpender.s 3 года назад

      @@CodeCat15 Sure, will subscribe you there also, thanks a lot again brother for the quality content.

    • @aafaqahmed2265
      @aafaqahmed2265 2 года назад

      Indeed @pushpender

  • @polu9132
    @polu9132 3 года назад +3

    Great work. keep posting videos on different topics related to iOS development. Kudos to you.👍

    • @CodeCat15
      @CodeCat15  3 года назад

      Thank you @polu and welcome to the channel

  • @pradipdeore8068
    @pradipdeore8068 2 года назад

    simple explanation yet very informative content.

  • @Real_Indian_bhartiya
    @Real_Indian_bhartiya 3 года назад +4

    your content and efforts are much appreciated

    • @CodeCat15
      @CodeCat15  3 года назад

      welcome to the channel Vaibhav, I am glad this video was helpful to you. Please do share this with your iOS group or with anyone who wants to know why test cases are so important and always feel free to ask question I will be happy to answer them

  • @tankarshah9913
    @tankarshah9913 2 года назад +2

    Very useful and conceptually explained all the things very clearly.
    Thank you Ravi sir for creating such a very fundamental and useful content for the community..!!

    • @CodeCat15
      @CodeCat15  2 года назад

      You are most welcome, do share the video with your iOS group and always feel free to ask questions

  • @govind20246
    @govind20246 3 года назад

    Simply awesome 👍

  • @prachibile2798
    @prachibile2798 2 года назад +2

    Hey @ravi. I am really a fan of yours. Whenever I want to learn anything in iOS then I search in your channel first and then I go through it. Your way of explanation is just awesome. Now I am doing unit testing for my project but using Quick and Nimble, Can you please make a video on Quick and Nimble especially UI Tests?

  • @arindamsantra1727
    @arindamsantra1727 2 года назад

    Great Content

  • @JunaidKhan-ny8tu
    @JunaidKhan-ny8tu 2 года назад

    Yar kya bat hy Ravi bhai ❤❤❤❤

  • @anshuiphonedevswiftandswif2107
    @anshuiphonedevswiftandswif2107 3 года назад +1

    Great work . Keep on more videos

    • @CodeCat15
      @CodeCat15  3 года назад +1

      Hello Anshu, welcome to the channel and thank you for your comment :)

  • @sambit6500
    @sambit6500 3 года назад +4

    It was really an Awesome video! It is very helpful for me, Thanks 🙏 & Merry Christmas 🎄

    • @CodeCat15
      @CodeCat15  3 года назад +1

      Hey Sambit, i am glad this video was helpful, do feel free to ask questions on this topic and do share this video with your iOS group. Merry Christmas to you too buddy

  • @Karma_Rinku
    @Karma_Rinku 3 года назад +1

    Video editing and all video delivery are great... Keep it up and video on all swift. docs topic ... For every chapter and each topic ..up to Advance level SwiftUI etc Thanks

    • @CodeCat15
      @CodeCat15  3 года назад

      I will try my best Karmjeet and thank you for your kind words

  • @connectSanjayMali
    @connectSanjayMali 2 года назад

    Kudos bro..

  • @DhavalHNena
    @DhavalHNena 3 года назад +1

    Nice example!

    • @CodeCat15
      @CodeCat15  3 года назад

      Glad that was helpful Dhaval

  • @rachitsharma8829
    @rachitsharma8829 Год назад +1

    Superb and Excellent explanation ... 👌

    • @CodeCat15
      @CodeCat15  Год назад

      I am glad this was helpful 👨‍💻

  • @surendramavuri9162
    @surendramavuri9162 3 месяца назад +1

    Very Good one. Thanks!

    • @CodeCat15
      @CodeCat15  3 месяца назад

      Glad you liked it!

  • @malleshaholeyache4464
    @malleshaholeyache4464 2 года назад +1

    Your explanation is awesome Ravi sir. I really loved this video 😍❤️. Keep posting such videos 😊.

    • @CodeCat15
      @CodeCat15  2 года назад

      Thank you so much 😀

  • @AnuragKashyap17
    @AnuragKashyap17 2 года назад +2

    I really like everything on this channel and the fact that you reply to each and every comment. Man!!!! you are doing a splendid job with so much of passion. A video on VIPER implementation from you will add something more to this channel. Thanks once again. PS: I would really like to buy you a pizza or a beer :p hehehehehe.... Keep it up!!

    • @CodeCat15
      @CodeCat15  2 года назад +2

      Thanks for the kind words Anurag it means a lot, VIPER is planned for next year along with other complicated topics which will be simplified soon.
      I also share some short videos on Instagram like a 2-3 min reels on swift so do check those out as well
      Pan base pizza is ❤️ but for now just share the channel with anyone who wants to learn swift or with your iOS group of company or WhatsApp or LinkedIn 😊

    • @AnuragKashyap17
      @AnuragKashyap17 2 года назад +1

      Few of your subscribers are known to me i have shared your channel to them and they are subscribed to you. And also I do want to buy a Pan pizza then for you. 😅😅

    • @AnuragKashyap17
      @AnuragKashyap17 2 года назад +1

      Please do not ever stop creating videos , soon your channel will be famous , it is slow process but then indeed a permanent one it will be.

    • @CodeCat15
      @CodeCat15  2 года назад +1

      I guess I would never stop making videos on Swift or anything related to iOS development, as when I was down and demotivated the iOS community took care of me and for that I am grateful and want to continue this work.

  • @kartheekmanthoju493
    @kartheekmanthoju493 3 года назад +1

    Excellent explanation

    • @CodeCat15
      @CodeCat15  3 года назад

      Glad it was helpful! Kartheek

  • @Real_Indian_bhartiya
    @Real_Indian_bhartiya 3 года назад +3

    keep on making such videos...

    • @CodeCat15
      @CodeCat15  3 года назад

      Thanks Vaibhav, I will surely keep on sharing whatever I learn or implement something new with everyone

  • @yogeshdate99
    @yogeshdate99 2 года назад +1

    great video Ravi...
    Definitely your video will add more value in to iOS engineer...
    Keep it up bro....

    • @CodeCat15
      @CodeCat15  2 года назад +1

      Thank you Yogesh, am glad the content is helpful. Do consider sharing the same with your iOS group 👍

  • @pankajchahakar8623
    @pankajchahakar8623 2 года назад

    Hi I love watching your sessions, it helps me a lot, I have request can you please make some videos on vip clean swift and unit test cases in vip clean swift

  • @shashankmishra5329
    @shashankmishra5329 3 года назад +1

    thanks for video!!

    • @CodeCat15
      @CodeCat15  3 года назад

      Welcome Shashank, please let me know if you have any questions on this topic and do share this with your iOS group on WhatsApp or Facebook

  • @museeransari8339
    @museeransari8339 3 года назад +1

    I am a big fan of you
    your explanation is awesome

    • @CodeCat15
      @CodeCat15  2 года назад

      Thank you so much 😀

  • @rishusharma8817
    @rishusharma8817 2 года назад +1

    Good job

    • @CodeCat15
      @CodeCat15  2 года назад

      Thank you, I am glad this was helpful.

  • @suhaspathak6319
    @suhaspathak6319 3 года назад +1

    Thanks for efforts to make a video. Can you make a video on API response model.

    • @CodeCat15
      @CodeCat15  3 года назад +1

      Hey Suhas can you elaborate more on the api response model please coz am sure the api series takes care about such models but i just wanted to be sure before I answer this question

  • @prafullkharche3835
    @prafullkharche3835 2 года назад

    Hey Ravi thanks for your video, i want to learn How to made SDK can you pls get a session of SDK Creation..it will helps to lots of people ..

  • @Hassankhan-cn9wu
    @Hassankhan-cn9wu 3 года назад +1

    Love from Pakistan bhai level ha apka

  • @sheshadrivendramishra1543
    @sheshadrivendramishra1543 2 года назад

    sir, i have a project with a chatting screen too in which i want to chat and along with i want send multiple image name, url, or multiple documents so how to do it???
    i did chatting for both sides receiver as well as sender and it is working well using table view.......but inside tableview i wanna take a collectionView in horizontal scrolling in which i want to send a url of image or any kind of documents(must be multiple) and and horizontal rows of must be tied with the row of tableView cell's row in which i am sending message but not others......don't want to use any third party or firebase..........so plz help me

  • @venugopalreddy6618
    @venugopalreddy6618 10 месяцев назад

    Can there be a source code , which is hard to write unit tests for?

  • @indivarraina5473
    @indivarraina5473 3 года назад

    Hi Ravi, Thanks for the video , was really looking for some test cases tutorials. I want to ask that the scenarios that you have passed through the test files, I also need to follow the same approach in my controller files too right ?

    • @CodeCat15
      @CodeCat15  3 года назад

      when you say controller files, do you mean UI test cases? or something else?

    • @raviphulara8165
      @raviphulara8165 10 месяцев назад

      Hi Sir, could you please share some UI test case demos?

  • @entertainmenton2106
    @entertainmenton2106 3 года назад

    Sir can you make video how to make project from basic step by step how to do Start and end in hindi .

  • @akanksha2143
    @akanksha2143 3 года назад +1

    hey CodeCat, please make a video on types of notifications.

    • @CodeCat15
      @CodeCat15  3 года назад +1

      I can show local notifications and cover all grounds with that but for push notification i need my own personal account and cannot use company account and the issue is I don’t have a personal account for APNS so showing just theory is something I don’t want to do coz for push notifications theory adds a less value than practical

    • @akanksha2143
      @akanksha2143 3 года назад

      Ok thanks. If you get time then start memory management topic also.

  • @nagarajvrao7249
    @nagarajvrao7249 3 года назад

    Can't we use protocol default implementation for logics instead of hard coding?
    Can't we define a protocol which we use for our logics in ViewModel/model/validator & use the same logic in test case?
    For ex.
    Protocol SomeProtocol {
    func getFullName(fName: String, lName: String) -> String
    }
    extension SomeProtocol {
    func getFullName(fName: String, lName: String)-> String {
    fName + lName
    }
    }
    struct ViewModel: SomeProtocol {
    }
    Class TestCase: SomeProtocol {
    XctAssertEqual(viewModel.getFullName("Code","Cat), self.getFullName("Code","Cat")
    //with this approach we can test all the values at once
    }

    • @CodeCat15
      @CodeCat15  3 года назад

      if i understand that right, you want to use the same protocol and write the business logic or should I say code from the view model or other layers in the extensions? Correct me if i got that wrong please but if I did get that right my question is why do you want to do code duplication at two places and what's stopping you to directly use the concrete implantation?

    • @nagarajvrao7249
      @nagarajvrao7249 3 года назад

      My point is It is better to re-use the same logic instead of hard coding the logic in the test case.
      For example If we are reading first name & last name from a JSON file, it will be easier to loop for all the values & assert In test case.
      func testNames() {
      users.forEach { user in
      let actual = viewModel.getFullname(user.firstName, user.lastName)
      let expected = getFullname(user.firstName, user.lastName)
      XctAssertEqual(expected, actual)
      }
      }

    • @CodeCat15
      @CodeCat15  3 года назад

      @@nagarajvrao7249 calling an actual API is preferred and let me tell you why Nagraj, sometimes when the server folks change the response key value then it will be easy to detect such hiccups because you are hitting a real server and not mocking the response from the server and I have had my fair share of pain in the past because some creative developer from the API team had different key-value pair on dev and different on QA, and if I did not have test cases I would have never caught such fantastic work of art done by the API team later i came to know that their deployment was failing to QA and they had no process so it was my test that caught it. I know once the QA was down and it was my test cases that caught it because my tests were failing. Having a JSON file locally will hide these kinds of issues

    • @nagarajvrao7249
      @nagarajvrao7249 3 года назад +1

      1.We can't call the API if it isn't ready
      2.If the API is dependent (on token...), we can't hardcode it.
      So Instead of directly calling the API, I thought of reading it from the local JSON & parse.
      Ofcourse If in the backend if the key value is updated, we can update the local JSON as well.
      I didn't get what issues you faced/ one might face? Can you explain (if not here may be in the next video)
      In your case key-values for development & staging were different?

    • @CodeCat15
      @CodeCat15  3 года назад +1

      Api when its ready can have issues and the local json file will never ever catch that issue coz the local file is not the place where api developers will make the change, or what if there’s a logical change?
      Also it will be a pain to maintain that local file in sync with server response, we cannot be sure that api response will never change coz changes do happen and we won’t work on the same project for 5 years someone else will maintain or pick it up
      So when they look at this wonderful test that pass but in reality due to server response changes or server not being live you are not getting the response so the test is really not helping us, it defects the whole purpose of having a test case in your project.
      Having a test case which does not really hit the server is not doing us any good, it will hide the potential issues that can arise on the server, the margin of error is a little high if we are not hitting the real server.
      The code that you will write to fetch the data will hit the server and not local json file so why have a local json file for test and a different route for the real implementation?
      The idea of test cases is to capture every potential bug and not to hide them, the local json file hides it as its not calling the real server.

  • @kurbanalimasu4895
    @kurbanalimasu4895 3 года назад

    Sir, I am getting error like this :
    /CoreData:1:1: API Misuse: Attempt to serialize store access on non-owning coordinator (PSC = 0x7fb68fc515d0, store PSC = 0x0)
    I am not using core data in my project although its showing like this !

    • @CodeCat15
      @CodeCat15  3 года назад +1

      You sure you are not having an xcdatamodel in your project? Can you also check app delegate to make sure there’s no start up code for core data?

    • @kurbanalimasu4895
      @kurbanalimasu4895 3 года назад

      @@CodeCat15 Yes Sir ! I am sure . I can also share a GitHub link

    • @CodeCat15
      @CodeCat15  3 года назад +1

      yeah sure go ahead, share the link please

    • @kurbanalimasu4895
      @kurbanalimasu4895 3 года назад

      @@CodeCat15 github.com/KurbanAli6615/ShoppingAppIOS
      Sir please replay ASAP

    • @kurbanalimasu4895
      @kurbanalimasu4895 3 года назад

      @@CodeCat15 Sir i have found error. Its showing error cause of assets. I have entered wrong type of asset

  • @songsmovieentertainment6691
    @songsmovieentertainment6691 2 года назад

    post the video English language

  • @randalnadadava9316
    @randalnadadava9316 3 года назад +1

    please speak hindi🙏

    • @CodeCat15
      @CodeCat15  3 года назад

      As i said earlier this is the video where english and hindi is mixed, but i am working on it and i assure you that next time it will be pure hindi so apologies for the same 😊