Why do we need testing in software and how to get started with Jest

Photo by Emile Perron on Unsplash

Why do we want to write test cases for our project?

Creating your first test case with Jest JS

test('My first Test', () => {}
The output for the above code
test('My failed test', () => {
throw new Error('Failed to execute!')
})
const multiplyNumber = (num1, num2) =>{
const total = num1 * num2
return total
}
module.exports = {
multiplyNumber
}
test('Should get me the right result', () => {const total = math.multiplyNumber(10,3)        if(total!=30){throw new Error('Total number should be 30! Got ' + total)         }})
Our test case is passed
const multiplyNumber = (num1, num2) =>{
const total = num1 * num2 - num1. //Subtracting num1 again
return total
}
test('Should get me the right result', () => {const total = math.multiplyNumber(10,3)expect(total).toBe(30) //Single line to check })

--

--

Start Up, I’m not so sure about the rest.

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

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