{"id":19053257,"url":"https://github.com/jotavare/unit-testing","last_synced_at":"2026-04-18T14:01:49.911Z","repository":{"id":250635146,"uuid":"834618805","full_name":"jotavare/unit-testing","owner":"jotavare","description":"Implemented a C++ function, learned how to use CMake and Google Test framework for unit testing.  Used a custom cpp devcontainer.","archived":false,"fork":false,"pushed_at":"2024-08-12T11:30:05.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-12T14:34:29.247Z","etag":null,"topics":["cmake","cmakelists","cpp","devcontainer","framework","google-test","makefile","nodejs","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jotavare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-27T20:32:53.000Z","updated_at":"2025-10-03T22:22:20.000Z","dependencies_parsed_at":"2024-11-08T23:30:00.320Z","dependency_job_id":"3a3d3044-95d9-4f3e-95b2-eed950c8348d","html_url":"https://github.com/jotavare/unit-testing","commit_stats":null,"previous_names":["jotavare/unit-testing"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jotavare/unit-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotavare%2Funit-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotavare%2Funit-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotavare%2Funit-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotavare%2Funit-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jotavare","download_url":"https://codeload.github.com/jotavare/unit-testing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotavare%2Funit-testing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31971489,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cmakelists","cpp","devcontainer","framework","google-test","makefile","nodejs","unit-testing"],"created_at":"2024-11-08T23:29:50.417Z","updated_at":"2026-04-18T14:01:44.892Z","avatar_url":"https://github.com/jotavare.png","language":"CMake","readme":"## ABOUT\n\nThis project involves creating and testing a function called `hasPair()` using modern `C++` practices. It required learning `CMake`, and using `GoogleTest` for unit testing. The project setup utilizes a devcontainer for `C++`, and `Node.js` for chapter exercises from `The Art of Unit Testing` (`aout3-samples/`).\n\n## PROJECT CHECKLIST\n\n- [X] [Introduction to unit testing.](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition)\n- [X] Implement the function `hasPair()`.\n- [X] Use Google Test, for unit testing the code.\n- [X] Remember to comment on the code where necessary.\n- [X] Publish the code on GitHub and send the link.\n- [X] **Bonus**: Set up the project with `CMake`.\n\n## PROJECT STRUCTURE\n\nThe current folder structure of the project and explanation of each folder and file:\n\n```bash\n├── .devcontainer/\n│   ├── cpp/\n│   │   ├── devcontainer.json   # devcontainer configuration file\n│   │   ├── Dockerfile          # Dockerfile for setting up devcontainer\n│   │   ├── post-create.sh      # script to run after creating the devcontainer\n│   │   └── reinstall-cmake.sh  # script to reinstall cmake\n│   ├── node/\n│   │   └── devcontainer.json   # devcontainer configuration file for aout3-samples\n├── aout3-samples/              # sample exercises from \"The Art of Unit Testing\" book\n├── cmake-tutorial/             # small tutorial i did to learn cmake\n├── exercise/\n│   ├── cmake/                  # includes a cmake update submodules file\n│   ├── example/                # cmake example i did to learn cmake and a makefile example\n│   ├── googletest/             # source code of googletest\n│   ├── hasPair/                # the main exercise, hasPair function and tests\n│   └── CMakeLists.txt          # main cmake configuration file\n├── .gitignore\n├── .gitmodules\n├── LICENSE\n└── README.md\n```\n\n## COMMANDS\n\nList of commands that I learned while doing this project:\n\n```bash\n# generate build system files in the 'build' directory\n# use --trace to show the commands being executed\ncmake -S . -B build\ncmake -S . -B build --trace\n\n# build the project using the generated build system files\n# use [n] (threads) to build or $(nproc --all) to use all threads\n# use --verbose to show the commands being executed\ncmake --build build -j [n]\ncmake --build build -j [n] --verbose\ncmake --build build -j $(nproc --all)\n\n# run the tests with coloured output and show output on failure\nGTEST_COLOR=1 ctest --test-dir build --output-on-failure\n\n# measure the time\ntime ccmake -S . -B build\n\n# measure the time\ntime cmake --build build\n\n# display the directory structure up to [n] levels deep\ntree -L [n]\n\n# list all installed vs Code extensions\ncode --list-extensions | xargs -L 1 echo code --install-extension\n\n# update the submodules\ngit submodule update --init\n```\n\n## FUTURE IDEAS\n\nThese are some ideas or improvements that I would make in the future:\n\n- [ ] Design a flow diagram of the project and the unit tests.\n- [ ] Create a CI/CD pipeline to automate the build and testing process, when code is pushed to the repository.\n- [ ] Create a `srand` vector, to test the code with a custom range, size and number of times.\n- [ ] Use a variable directly while building the project. `cmake -S . -B build -D vector=\"1,2,3,4,5\"`\n- [ ] Instead of symlink the latest version of Google Test, use a release version or fetch the latest version with `cmake`.\n- [ ] Currently, I have to build again with `cmake --build build` so the tests can be disabled/enabled. Find if this is the intended behaviour.\n\n## REFERENCES\n\nSome references that I used or will in the future, to learn and complete this project. Some are based on the book `The Art of Unit Testing`.\n\n| Book | Author |\n| :--- | :----- |\n| Working Effectively with Legacy Code (Pearson, 2004) | `Michael Feathers` |\n| The Complete Guide to Software Testing (Wiley, 1988) | `Bill Hetzel` |\n| XUnit Test Patterns (Addison-Wesley Professional, 2007) | `Gerard Meszaros` |\n| Unit Testing Principles, Practices, and Patterns | `Vladimir Khorikov` |\n| Test-Driven Development: By Example (Addison-Wesley Professional, 2002) | `Kent Beck` |\n| Growing Object-Oriented Software, Guided by Tests (Addison-Wesley Professional, 2009) | `Steve Freeman` and `Nat Pryce` |\n| Clean Code (Pearson, 2008) | `Robert C. Martin` |\n\n| Websites | Source |\n| :--- | :----- |\n| [Command Query Separation](https://martinfowler.com/bliki/CommandQuerySeparation.html) | `Website` |\n| [XUnit Test Patterns](https://xunitpatterns.com) | `Website` |\n| [Node.js’s assert module](https://nodejs.org/api/assert.html) | `Website` |\n| [GoogleTest Primer](https://google.github.io/googletest/primer.html) | `Website` |\n| [GoogleTest Assertions Reference](https://google.github.io/googletest/reference/assertions.html) | `Website` |\n| [CPP Devcontainer](https://github.com/microsoft/vscode-remote-try-cpp) | `GitHub` |\n| [GNU Smalltalk User's Guide: SUnit - Kent Beck](https://www.gnu.org/software/smalltalk/manual/html_node/SUnit.html) | `Website` |\n\n| Videos |\n| :--- |\n| [CMake - the essential package](https://www.youtube.com/watch?v=UH6F6ypdYbw) |\n| [Do you even test? (your code with CMake)](https://youtu.be/pxJoVRfpRPE?si=-A3eVD9pUFIryHTY) |\n| [GoogleTest Introduction with CMake LINUX - C++ - GMOCK](https://youtu.be/zfgFphZ63UY?si=lWw49Dj72T1CLZIF) |\n\n## UNIT TEST CHECKLIST\n\nThis section includes some checklists and questions from the book `The Art of Unit Testing`, which I found useful to remember when writing unit tests.\n\n### UNIT TEST PROPERTIES\n\n\u003e A good unit test should exhibit the following properties:\n\n- [ ] It should be easy to understand the intent of the test author.\n- [ ] It should be easy to read and write.\n- [ ] It should be automated.\n- [ ] It should be consistent in its results (it should always return the same result if you don’t change anything between runs).\n- [ ] It should be useful and provide actionable results.\n- [ ] Anyone should be able to run it with the push of a button.\n- [ ] When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem.\n\n### UNIT TEST QUESTIONS\n\n\u003e Ask yourself the following questions about the tests you’ve written and executed up to now:\n\n- [ ] Can I run and get results from a test I wrote two weeks, months or years ago?\n- [ ] Can any member of my team run and get results from tests I wrote two months ago?\n- [ ] Can I run all the tests I’ve written in no more than a few minutes?\n- [ ] Can I run all the tests I’ve written at the push of a button?\n- [ ] Can I write a basic test in no more than a few minutes?\n- [ ] Do my tests pass when there are bugs in another team’s code?\n- [ ] Do my tests show the same results when run on different machines or environments?\n- [ ] Do my tests stop working if there’s no database, network, or deployment?\n- [ ] If I delete, move, or change one test, do other tests remain unaffected?\n\n### UNIT TEST QUALITIES\n\n\u003e A good unit test has these qualities:\n\n- [ ] It should run quickly.\n- [ ] It should have full control of the code under test.\n- [ ] It should be fully isolated (it should run independently of other tests).\n- [ ] It should run in memory without requiring filesystem files, networks, or databases.\n- [ ] It should be as synchronous and linear as possible (no parallel threads).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjotavare%2Funit-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjotavare%2Funit-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjotavare%2Funit-testing/lists"}