Importance of Unit tests — My journey with Unit-tests 2

#include <cstddef>

class LinkedList{
int value {0};
LinkedList* nextNode {NULL};

LinkedList* addNewNode(int nodeVal){

LinkedList *newNode;
newNode->value = nodeVal;
newNode->nextNode = nullptr;

return newNode;
linkedlist = addNewNode(5);

EXPECT_TRUE(linkedlist != nullptr);
EXPECT_TRUE(linkedlist->nextNode != nullptr);
Segmentation fault
LinkedList* getANodeWithGivenValue(LinkedList *existingList,int value){   while (existingList != NULL){      if(existingList->value == value){          return existingList;
existingList = existingList->nextNode;
TEST_F(LinkedListTest,getANodeWithGivenValueNoMatchingValueReturnsFalse){    LinkedList *existingList = addNewNode(1);    LinkedList *nodeWithTheGivenValue =     getANodeWithGivenValue(existingList,5);    EXPECT_TRUE(nodeWithTheGivenValue->nextNode == nullptr);    EXPECT_EQ(nodeWithTheGivenValue->value,0);




DevOps who is willing to learn and try new things.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Scaling Scrum by a series of experiments

Introduction to XLM1

My Journey to becoming a Full Stack Web Developer

Release Wrap Up — August 2020

Backup & Restore data in ‘etcd’

10 Web Developer Portfolio Tips

Why we left Flask for Django

The never ending game: ‘Asynchronous vs Synchronous’.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sachith Muhandiram

Sachith Muhandiram

DevOps who is willing to learn and try new things.

More from Medium

Diff between (a+b)/2 and a+(b-a)/2

Introduction to Oracle Database Management -5

Getting Started With Version Control Systems -A practical approach on git

Heap Sort — [Introduction to Algorithms]