C++ Unit Testing with Google Test Tutorial

Sdílet
Vložit
  • čas přidán 31. 08. 2015
  • In this tutorial, we take a look at how to perform using testing in C++ using the Google Test framework and ReSharper C++ as the test runner. To find out more about ReSharper C++, please visit:
    www.jetbrains.com/resharper-cpp
    Author: Dmitri Nesteruk
  • Věda a technologie

Komentáře • 84

  • @KangJangkrik
    @KangJangkrik Před 3 lety +21

    The moment you realized JetBrains didn't "dog food" their C++ IDE on this tutorial

  • @jflopezfernandez
    @jflopezfernandez Před 6 lety +18

    This was an amazing tutorial. Would love to see another one specifically with any nuances in CLion or maybe some for advanced features, but this was great, thank you

  • @syntaxusdogmata3333
    @syntaxusdogmata3333 Před 8 lety +23

    7:09 - Great example of parameterized testing in Google Test.

  • @MrBasania
    @MrBasania Před 5 lety +2

    ReSharper seems to be a great extension, the refactoring features are much more advanced comparing to the ones that VS has.

  • @baqtronic7704
    @baqtronic7704 Před 5 lety +2

    Awesome step-by-step! Thank you very much!

  • @dmanikhine
    @dmanikhine Před 3 lety +8

    Коротко и по делу. Огромное спасибо автору!

  • @ihspan6892
    @ihspan6892 Před 2 lety +1

    Thank you, very clear and straightforward.

  • @johngalt7704
    @johngalt7704 Před 4 lety +2

    Большое спасибо за проделанную работу!

  • @arthurspa
    @arthurspa Před 4 lety +2

    Really good example of how to use gtest.

  • @zenoncelofan5768
    @zenoncelofan5768 Před 4 lety +1

    Historical note: Before February 2016 *_EQ had a convention of calling it as ASSERT_EQ(expected, actual), so lots of existing code uses this order. Now (2020) *_EQ treats both parameters in the same way. However, when possible, ASSERT_EQ(actual, expected) is preferred. (gtests docs)

  • @zianaris2150
    @zianaris2150 Před 6 lety +2

    Good one. Please do another video for gmock.

  • @patrickhentschel5300
    @patrickhentschel5300 Před 7 lety

    only opens some text in the console for me, not in Visual Studio. Did i miss something?

  • @placeforpeace1562
    @placeforpeace1562 Před 5 lety

    i got error in the INSTANTIATE_TESTCASE_P like function definition not found . what do i do now;

  • @venkateswarans1012
    @venkateswarans1012 Před 4 lety +7

    Best way to do this in Linux

  • @sharathmanchala6571
    @sharathmanchala6571 Před 4 lety +3

    very useful for beginners

  • @mathssoso4261
    @mathssoso4261 Před 2 lety

    Could you just explain how did you create the base project, stdafx.h and targetver.h, I can't make this compile, vs can't find the test in test explorer

  • @smajin28
    @smajin28 Před 2 lety +1

    0:40 Already on it. This is what I want to know. Where did he earn this stuff. How could I have possibly known to do that without this video. This all had to start somewhere.

  • @thegod3500
    @thegod3500 Před 7 lety

    What is unit test session page in your VS, and where i can find its?

    • @dariadovzhikova418
      @dariadovzhikova418 Před 7 lety

      This is ReSharper Unit Test Session tool window (www.jetbrains.com/help/resharper/2016.2/Using_Unit_Test_Sessions.html) If you have ReSharper and/or ReSharper C++ installed it should be available in ReSharper | Windows | Unit Test Sessions.

  • @helloworld8583
    @helloworld8583 Před 3 lety

    Thank you!!!!!!!!!!! =*) Спасибочки! Дякую!

  • @hitarthmukundraykanakia3137

    Is this present in Clion?

  • @ksenichiro5417
    @ksenichiro5417 Před 5 lety +1

    Спасибо за ролик, хороший английский, кстати

    • @pectusin
      @pectusin Před rokem

      I'm not surprised, Dmitri gradated from University of Southampton, UK ))

  • @theycallmemorphine
    @theycallmemorphine Před 3 lety

    Does anyone know whats the version of the latest Google test

  • @ali57555
    @ali57555 Před rokem

    We need a Clion tutorial please

  • @renekomane
    @renekomane Před 5 lety

    Is it possible to using googletest and C++ to run automation test on chrome ? Like insert an user and psw in a web page a login automatically ?

    • @JetBrainsTV
      @JetBrainsTV  Před 5 lety

      Hello Alexander,
      thank you for contacting us.
      With ReSharper C++ you could run google tests inside Visual Studio: www.jetbrains.com/help/resharper/Unit_Testing_in_CPP.html
      Thank you!

  • @rocky6162
    @rocky6162 Před 3 lety +2

    why set the field to a pointer (BankAccount*) instead of just the object itself at 4:56?

    • @RollerBladingSports
      @RollerBladingSports Před rokem

      Without pointer you'll call it by value, but you should call it by reference. hope this one is still actual :D

  • @decky1990
    @decky1990 Před rokem

    Why would you use Google Test over asserts or static_asserts?

  • @viorelcasapu9951
    @viorelcasapu9951 Před 6 lety +2

    nice video. Could you make a video about unit testing using also mock files? it will be great

    • @olgarodygina5127
      @olgarodygina5127 Před 6 lety +1

      Hello Viorel! Thank you for feedback. We will consider such possibility. Thank you!

    • @kpanat
      @kpanat Před 7 měsíci

      As I remember this is in Qt,isn't it? So I don't forget all else...

  • @rituexplorer
    @rituexplorer Před 3 lety

    Please make a video on mocking free functions

  • @placeforpeace1562
    @placeforpeace1562 Před 5 lety

    could u please give the actual source code of this video

  • @ductamnguyen8257
    @ductamnguyen8257 Před 4 lety

    what is the shortcut keyboard to generate the constructor ?? Can anyone help me with that? Thank you

    • @JetBrainsTV
      @JetBrainsTV  Před 4 lety

      Maybe this will help - www.jetbrains.com/help/resharper/Code_Generation__Type_Constructors.html

  • @advaitharmy
    @advaitharmy Před 6 lety

    When I try to add "account_state {100, 50, 50, true}",I am getting error "expected '(' for function-style cast or type construction". Can any one help me?

    • @nastasiak2512
      @nastasiak2512 Před 6 lety

      Could you share a full sample? Where do you get the error btw? In the IDE or during the compilation?

  • @wenyangzhao6026
    @wenyangzhao6026 Před 8 lety +12

    why not CLion?

    • @soloondotnet
      @soloondotnet Před 8 lety +1

      +Wenyang Zhao Google Test support in CLion is coming, too!

  • @ignacioswboada660
    @ignacioswboada660 Před 2 lety

    Link to the code of the video?

  • @andriykuz1140
    @andriykuz1140 Před 8 lety

    Hi, I have such error when running tests: 'Can't run "path" --gtest_list_tests" witch working directory "path": Can't create process'. Maybe someone meet this error?

    • @olgarodygina5127
      @olgarodygina5127 Před 8 lety

      +Andriy Kuz Could you please download and install the latest ReSharper Release 2016.1 and check if the issue is still present for you? If it won't help could you please send to me some sample solution with this issue to olga.rodygina at jetbrains dot com? Thank you!

  • @jdleanne
    @jdleanne Před 3 lety

    can we have an updated version?

    • @JetBrainsTV
      @JetBrainsTV  Před 3 lety +1

      We'll definitely plan updating the content. However, except for the UI, not many things changed.

    • @jdleanne
      @jdleanne Před 3 lety

      @@JetBrainsTV yes please. Most videos. Including the paid ones are out dated :(

  • @Bill-gc9bt
    @Bill-gc9bt Před 5 lety +17

    I understand that you're a genius at this stuff, but can you provide a reference for those of us that are new to google test? You know, where every single detail (no matter how small you think it is) is thoroughly explained. Feel free to tell me that I'm a lost cause, if that is indeed the case. Thanks in advance.

  • @deadsoul181
    @deadsoul181 Před 3 lety +7

    Дима а можно по-русски?

  • @stana.281
    @stana.281 Před 4 lety

    0:10 - And if you're not using Visual Studio?

    • @ivanenzhaev2373
      @ivanenzhaev2373 Před 3 lety +1

      I use QtCreator IDE. You can setup GTest and GMock very quickly:
      1) Select "File" > "New Project" > "Other Project" > "Auto Test Project".
      2) Next, in drop down list ("Test framework") select "Google Test". Choose the source code folder of Google Test (that you get from GithUb) for example: "E:\Libs\googletest-release-1.10.0". Google Mock will be included too.

  • @KangJangkrik
    @KangJangkrik Před 3 lety

    Would be better if you move the definitions into header file

  • @kpanat
    @kpanat Před 7 měsíci

    Here all fields are public. But how test privatr fields?

  • @TroyBreaker
    @TroyBreaker Před 8 měsíci

    Спасибо, но что делать, если мой класс в отдельном .h файле?

  • @skell1
    @skell1 Před 5 lety +2

    How come we aren't using CLion? If C++ was included in the features for Resharper, I would have bought that instead. Sigh.

  • @rishabhagarwal3404
    @rishabhagarwal3404 Před 5 lety

    If anyone is having issue with installation and writing basic test. I have added a guide to installation with some sample code.
    github.com/rishabh-agarwal/googleTestDemo
    Hope this helps

  • @chenyangliu9120
    @chenyangliu9120 Před 2 lety

    I wonder how it ran without return value for BankAccount::withdraw

    • @chenyangliu9120
      @chenyangliu9120 Před 2 lety

      I mean at first, this bool function without a return should cause the program compiling into Error

  • @Roanoked
    @Roanoked Před rokem

    "if you use visual studio" ... no, I'm using a CMake based project structure with CLion 😅

  • @spicytuna08
    @spicytuna08 Před 6 lety +2

    why not use class instead of struct?

    • @reysabs
      @reysabs Před 5 lety

      Mostly in C++ use struct if you can to avoid possible memory leak cause struct is a valued type and it was manage by OS that means you dont need to release or delete.

    • @GuyCollinsWilliam
      @GuyCollinsWilliam Před 5 lety +1

      I was thinking exactly the same thing.

    • @m3tsAEp31kk0
      @m3tsAEp31kk0 Před 5 lety +10

      @@reysabs I don't know where you're getting your "information" but that is not correct. Structs work exactly like classes except for the default visibility of members.

    • @reysabs
      @reysabs Před 5 lety

      Im sorry I was referring for creating a Data structure. I used C++ for cross platform mobile development. IOS prefer struct over Class on this matters. I only use Class for methods or anything needs inheritance cause C#, Swift and Java doest support multiple inheritance.

    • @HermanWillems
      @HermanWillems Před 5 lety

      I got a more important question: Why people use inheritance so much. It breaks encapsulation. Use composition as much as possible. People are thought wrongly in the past.

  • @jeensdeleted
    @jeensdeleted Před rokem

    Unclear how to get this "NuGet Packages" =/

  • @spicytuna08
    @spicytuna08 Před 6 lety +8

    lol. test code is 100 times longer/complicated than actual code. it takes more brain to write test code than actual code.

    • @MistahJuicyBoy
      @MistahJuicyBoy Před 5 lety +3

      80% (at least for me) of writing code is debugging, and writing test code cuts into that time.

  • @huyvole9724
    @huyvole9724 Před 4 lety

    So fast

  • @dinobulja
    @dinobulja Před 3 lety

    19 errors at the start already, not compiling
    Severity Code Description Project File Line Suppression State
    Error C4996 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED. You can define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to acknowledge that you have received this warning. ExploreGoogleTest \\folderredirect\frrp-data02\ki0v\desktop\work\cpp\exploregoogletest\packages\googletest.1.8.3\build
    ative\include\gtest\gtest-printers.h 632

  • @gabrielmalek7575
    @gabrielmalek7575 Před rokem

    Please use dark mode, my eyes are on fire

  • @Eminosrrr
    @Eminosrrr Před 6 lety

    hard german accent

  • @aminbe3079
    @aminbe3079 Před 6 lety +1

    I don't understand the point of unit testing anyway, why not just compile your program the normal way and test it ?!

    • @prezadent1
      @prezadent1 Před 6 lety +4

      The tests are for future use so when you make changes the tests can verify that the results are still valid.

    • @Hypersion
      @Hypersion Před 6 lety +6

      Imagine you have a program with 10 Millions lines of code written by dozens of different people and you want to add or change a feature or fix a bug. How do you do that and make sure you don't break the rest of the code base. Simple, you use tests.

    • @jayands
      @jayands Před 5 lety

      Tests are for when you go to modify the code. If you didn't write it, or even if you did but some time ago, you can look at it and see that this is what is supposed to happen. Combined with code coverage, it can eliminate a ton of bugs before they get released, both subtle and glaring. As an oversimplified example, ever been to r/GamePhysics on Reddit? Ideally, those could have been caught with unit and behavior testing

  • @markgraham2312
    @markgraham2312 Před 6 lety +2

    This video is an advertisement for resharper. Unit Tests are not done like this at all. Unit Tests test source code. There is no source code here. Just code created for the unit test.