I Asked Copilot To Write Unit Tests - It Wasn’t Great

Поделиться
HTML-код
  • Опубликовано: 10 фев 2025
  • Become a patron and gain access to source code and exclusive live streams: / i-asked-copilot-81689403
    Learn how to harness the power of GitHub Copilot with Visual Studio Code for generating C# unit tests using xUnit. I will walk you through the process, highlighting the strengths and limitations of Copilot, and share valuable tips on developing an effective strategy for writing unit tests.
    As you will witness, Copilot often struggles to understand the context and generate test cases that are substantially different from the ones written already - which is the core purpose of testing! In this video, we will experiment with various approaches, such as providing more detailed method signatures and parameter names. Through trial and error, we discover that Copilot might work best when given more explicit guidance through comprehensive method names and parameters rather than using written requests.
    In addition to the context-related issues, you will see that Copilot sometimes generates code that doesn't compile or fails to identify corner cases. These are serious impediments when writing unit tests. However, we could overcome these limitations by actively guiding Copilot and serving it with corner cases.
    By the end of the video, we successfully implement a function and its corresponding unit tests, showcasing that with the right strategy, Copilot can be an effective tool for writing unit tests.
    Thank you so much for watching! Please like, comment & share this video as it helps me a ton!! Don't forget to subscribe to my channel for more amazing videos and make sure to hit the bell icon to never miss any updates.🔥❤️
    ✅🔔 Subscribe ► / @zoran-horvat
    ⭐ Learn more from video courses:
    Beginning Object-oriented Programming with C# ► codinghelmet.c...
    ⭐ Collections and Generics in C# ► codinghelmet.c...
    ⭐ Making Your C# Code More Object-oriented ► codinghelmet.c...
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    ⚡️ Have a look at our other Videos :
    👉 Using GitHub Copilot to Write Complex Code | Step-by-step Tutorial ► • Using GitHub Copilot t...
    👉 Coding with GitHub Copilot - Beginner to Master | VS Code Demo ► • A Comprehensive Guide ...
    👉 What is Covariance and Contravariance in C# ► • What is Covariance and...
    How to Initialize a Clean ASP.NET Core Project with Entity Framework Core and Identity ► • How to Initialize a Cl...
    👉 The Null Conundrum: A Guide to Optional Objects in C# ► • How to Avoid Null Refe...
    ⚡️Chapters:
    ▬▬▬▬▬▬▬▬▬▬▬
    ⌚ Intro


    ⌚ Outro
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    #zoranhorvat
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    ⭐ CONNECT WITH ME 📱👨
    🌐Buy me a Coffee ► ko-fi.com/zora...
    🗳 Pluralsight Courses ► codinghelmet.c...
    📸 Udemy Courses ► codinghelmet.c...
    📸 Join me on Twitter ► / zoranh75
    🌐 Read my Articles ► codinghelmet.c...
    📸 Join me on LinkedIn ► / zoran-horvat
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    👨 About Me 👨
    Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017 I have started publishing professional video courses at Pluralsight and Udemy and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my RUclips channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    ⚡️RIGHT NOTICE:
    The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our youtube channel, in general, may contain certain copyrighted works that were not specifically authorised to be used by the copyright holder(s), but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
    ⭐For copyright or any inquiries, please contact us at zh@codinghelmet.com

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

  • @konradhylton
    @konradhylton Год назад +2

    "Will it not eat and then prepare it's own dogfood?" Asking the serious questions. Subscribed.

  • @silkogelman
    @silkogelman Год назад +3

    Thank you Zoran, very interesting.
    I hope the upcoming Copilot Chat feature will provide more ways to make Copilot produce better tests.

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

    TDD application of Copilot would be interesting to see, although I have my doubts))

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

    You could press `alt + ]` to cycle through copilot suggestions I believe. So you can try that when it tries to “talk back” to you as you say

    • @zoran-horvat
      @zoran-horvat  Год назад +3

      While that is true that it might sometimes offer a better solution in the alternatives, I never got accustomed to break the flow and read those. Actually, my impression was that using Copilot in that mode of operation doesn't save any time - and that is the primary need I have.
      I generally don't need it to write my code, I need it to write it faster than I would do. In that respect, Copilot has one chance to intervene at any given time, and if that is the miss, I get on to writing the solution myself, hoping that it will catch up at some point during the process.

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

    Hi thank you for the video; from my experience, chatgpt4 is quite good at generating code if I first show him templates informing it on how I want my test to look, which nuget (it does well with C# functionnal library LanguageExt), which approach/style etc.); I havent tried for TDD though (kind of scare) but do you think it might be a viable option or does the "context"-problem still holds?

  • @1usrname
    @1usrname Год назад

    Thanks Zoran. I found your coverage of CoPilot very informative. However, I am more interested in TDD and how CoPilot can help. Is it possible to have CoPilot help write code that can pass existing tests?

    • @zoran-horvat
      @zoran-horvat  Год назад

      I still haven't experimented with that, because it generally failed to generate good code for any kind of tests. I was more focused on making it write tests first, and that didn't work out well either.

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

    I hope Copilot learns from the changes that developers make to its suggestions.

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

    Me, I was screaming TDD from the beginning.

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

    I think a neat approach would be to write unit tests by hand, and then see what AI could do when asked "hey, write this code!"
    Could work a treat if you're certain about the units of your design, but the implementation is hard or unknown

    • @zoran-horvat
      @zoran-horvat  Год назад +2

      There will be the video that does that! I am waiting to get access to Copilot X before recording.

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

    What is TDD?

    • @zoran-horvat
      @zoran-horvat  Год назад

      Test-Driven Development

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

      Transmitted Dermatology Disease