Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Figuring Out How to Test Code

Figuring Out How to Test Code

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13495640
    wrote on last edited by
    #1

    I've been familiar with C++ for a few years now but I can't seem to think of a good solution for debugging my code. Can anyone make a suggestion?

    L J T 3 Replies Last reply
    0
    • U User 13495640

      I've been familiar with C++ for a few years now but I can't seem to think of a good solution for debugging my code. Can anyone make a suggestion?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use the debugger.

      U 1 Reply Last reply
      0
      • L Lost User

        Use the debugger.

        U Offline
        U Offline
        User 13495640
        wrote on last edited by
        #3

        I should probably have mentioned. It's a class file, not a full program. I'm using Visual Studio Code and the Debugger wants an executable to run but I haven't even compiled the file.

        V L CPalliniC 3 Replies Last reply
        0
        • U User 13495640

          I should probably have mentioned. It's a class file, not a full program. I'm using Visual Studio Code and the Debugger wants an executable to run but I haven't even compiled the file.

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Then you have first to compile and link it! BTW, is this file already a part of some project?

          1 Reply Last reply
          0
          • U User 13495640

            I should probably have mentioned. It's a class file, not a full program. I'm using Visual Studio Code and the Debugger wants an executable to run but I haven't even compiled the file.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You cannot test a class file in isolation, it must be part of an executable. And if you have not even compiled it yet, you are quite a way from that step. I would suggest getting a copy of Visual Studio 2017 (free from Microsoft) and using the tools that come bundled with that.

            1 Reply Last reply
            0
            • U User 13495640

              I've been familiar with C++ for a few years now but I can't seem to think of a good solution for debugging my code. Can anyone make a suggestion?

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              Between your subject and your post it is not clear what you want to do. If you want to formally 'test' your code then 1. Research unit test libraries and select one 2. Add the library to your project (not part of production delivery) 3. Use the library and write unit test code to test both happy path, boundaries and failure cases. 4. Run the unit tests. If you want to information test your code then 1. Create ANOTHER project 2. COPY your class to it 3. Add a second class with a main method 4. Write a number of methods that exercise the code. 5. Build and run it. 6. If you make changes copy it back. If you already know the class has a problem and you cannot not determine what the problem is 1. Find a way to replicate the problem (see two above examples.) 2. As per the other posts find a debugger and figure out how it works. 3. Step through your code in the debugger to find the problem. Note that if you have large application and you already know that your class is failing then attempting to debug the entire application just so you get to the class is not very effective.

              1 Reply Last reply
              0
              • U User 13495640

                I've been familiar with C++ for a few years now but I can't seem to think of a good solution for debugging my code. Can anyone make a suggestion?

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                Do you think is there any other or rather say faster way to remove the bug from solution! I doubt there is any. I remember when I don't know how to debug the MFC application, I used to put MessageBox to identify the pain areas. You think how many time have to run application just to point the pain location, if I know how F9,F5 and F10 work at that time, my time would be reduced by 99% in my case.

                1 Reply Last reply
                0
                • U User 13495640

                  I should probably have mentioned. It's a class file, not a full program. I'm using Visual Studio Code and the Debugger wants an executable to run but I haven't even compiled the file.

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Of course your code must first compile. Then you could make a simple executable just for testing it, i.e. stressing the class features by fully using its public interface.

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups