Hard Prerequisites |
IMPORTANT: Please review these prerequisites, they include important information that will help you with this content. |
|
Your directory structure should look like this:
├── requirements.txt
└── consume_github_api
│ └── consume_github_api.py
└── tests
└── ...?
Your directory structure should look like this:
├── spec
| ├── support
| | └── jasmine.json
| └── ???
├── src
| └── consume_github_api.js
└── package.json
Remember to export your function:
module.exports = { YOUR_FUNCTION_NAME };
The directory structure should look like this:
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── app
├── build.gradle
└── src
├── main
│ └── java
│ └── consume_github_api
│ └── ConsumeGithubAPI.java <-------- names are important
└── test
└── java
└── consume_github_api
└── ???.java <-------- names are important
Your mission is to test your project. But it is important that your tests don’t actually make any api calls. If you are not connected to the internet at all then your tests should still be useful.
A useful test gives us confidence that the code does what it is meant to do.
If you do anything that looks like the following pseudocode then you are doing it wrong
spyOn(myFunction) // mock a function
myFunction() // call the mocked function
assert myFunction.wasCalledOnce // expect that the mocked function was called. Because you just called it this will always pass. So the test is useless.
The above adds no confidence in the code under test since the code under test wasn’t even used.
Here is a useful way to think about mocks and spies:
Making API calls is considered “expensive”. Why? Because
You also want to make sure that your tests can pass even if there ius no internet connection.
You need to test that when you want to make an api call then:
You don’t want your unit tests to make api calls. You just want them to prove that the part of your machine that makes those calls is being used correctly.
As another example, if you were developing a “forgot password” or “confirm email address” function for a website then you would test pretty much the same thing. You need to make sure that the correct functionality gets evoked, without actually sending any emails.