Mobile Development and JavaScript | Module 4
Course Name: Mobile Development and JavaScript
Course Link: Mobile Development and JavaScript
These are Mobile Development and JavaScript Week 4 Coursera Answers
Programming Assignment: Writing a Unit Test
Task 1: Add Jest as a devDependency
Open your terminal and make sure you’re in the jest-testing
directory.
Run the following command to install Jest as a devDependency:
npm install jest --save-dev
Task 2: Update these code and save files:
package.json:
{ "name": "jest-testing", "version": "1.0.0", "description": "", "main": "timesTwo.js.js", "scripts": { "test": "jest" }, "devDependencies": { "jest": "^28.0.0" }, "author": "", "license": "ISC" }
timesTwo.js:
function timesTwo(number) { return number * 2; } module.exports = timesTwo;
timesTwo.test.js:
const timesTwo = require('./timesTwo'); test('returns the number times 2', () => { expect(timesTwo(10)).toBe(20); });
Task 3: Submit assignment.
These are Mobile Development and JavaScript Week 4 Coursera Answers
Module 4 Quiz: Programming Paradigms
Q1. The idea of having separate, small pieces of code that are easy to test is called what?
- Unit testing
- Integration testing
- End-to-end testing
- Post-hoc testing
Answer: Unit testing
Q2. Which of the following is a framework that can help you run a unit test?
- Jest
- JFrame
- JavaFrame
- JavaTest
Answer: Jest
Q3. When the following test executes, what will the test result be?
function multiply(a, b) { return a; } expect(multiply(2, 2)).toBe(4);
- Success.
- Fail.
Answer: Fail.
These are Mobile Development and JavaScript Week 4 Coursera Answers
Q4. When the following test executes, what will the test result be?
function subtract(a, b) { return a – b; } expect(subtract(10, 4)).toBe(6);
- Success.
- Fail.
Answer: Success.
Q5. True or False: End-to-end testing is the slowest and most expensive type of testing.
- True.
- False
Answer: True.
Q6. What is End-to-end testing (e2e)?
- End-to-end testing is testing how parts of your system interact with other parts of your system.
- End-to-end testing is a comprehensive test that starts at the beginning of your code and runs to the end.
- End-to-end testing revolves around the idea of having separate, small pieces of code that are easy to test.
- End-to-end testing tries to imitate how a user might interact with your application.
Answer: End-to-end testing tries to imitate how a user might interact with your application.
These are Mobile Development and JavaScript Week 4 Coursera Answers
Q7. What is Code Coverage?
- A measure of what percentage of your code is covered by tests.
- What percentage of your code is complete.
- A measure of what percentage of your code has failing tests.
- What percentage of your code is in Javascript.
Answer: A measure of what percentage of your code is covered by tests.
Q8. The development of Node.js led to the ability to do which of the following?
- Write full-stack JavaScript programs.
- Estimate code coverage
- Download and manage packages
- Run unit tests
Answer: Write full-stack JavaScript programs.
Q9. Which of the following runtimes are typically used for building backends?
- Node.js
- Cyprus
- Jest
- Protractor
Answer: Node.js
These are Mobile Development and JavaScript Week 4 Coursera Answers
Q10. Integration testing is defined how?
- Testing how parts of your system interact with other parts of your system.
- Testing revolves around the idea of having separate, small pieces of code that are easy to test.
- Testing tries to imitate how a user might interact with your application.
- Testing how much of your code is covered by tests.
Answer: Testing how parts of your system interact with other parts of your system.
Q11. Which of the following is testing how parts of your system interact with other parts of your system?
- Unit testing
- Post-hoc testing
- End-to-end testing
- Integration testing
Answer: Integration testing
Q12. Which of the following are NOT one of the three types of testing?
- End-to-end testing
- Unit testing
- Post-hoc testing
- Integration testing
Answer: Post-hoc testing
These are Mobile Development and JavaScript Week 4 Coursera Answers
Q13. Which command is used to install a Node package?
- npm
- pkg
- node
- package
Answer: npm
Q14. package.json is used to do which of the following?
- Store all the testing code.
- Turn your code into an application.
- Store all the dependencies required for application.
- Download npm packages.
Answer: Store all the dependencies required for application.
Q15. True or False: If you have built a project with different node packages, they will all be listed inside the package.json file.
- True
- False
Answer: False
These are Mobile Development and JavaScript Week 4 Coursera Answers
Q16. True or False: End-to-end tests can be performed in a web browser without writing code.
- True
- False
Answer: True
Q17. A person on your team wants to help with testing. However, they are not a developer and cannot write code. What type of testing is most suited for them?
- End-to-end testing
- Post-hoc testing
- Unit testing
- Integration testing
Answer: End-to-end testing
Q18. In Jest you use mocking by employing which of the following?
- External mock libraries
- Jest Fakes
- Jest Mock functions
- Jest Snapshot
Answer: Jest Mock functions
These are Mobile Development and JavaScript Week 4 Coursera Answers
Q19. What is the recommended way to separate the code that you are testing from its related dependencies?
- Mocking
- End-to-end testing
- module.exports
- Fakes
Answer: Mocking
These are Mobile Development and JavaScript Week 4 Coursera Answers
More Weeks of this course: Click Here
More Coursera Courses: http://progiez.com/coursera