Deno Built-In Test Runner Essentials Quiz Quiz

Explore essential concepts of Deno's built-in test runner with beginner-friendly questions covering its features, basic syntax, and common practices in automated testing. Ideal for users wanting to strengthen their understanding of Deno’s native test utilities and capabilities.

  1. Identifying the Core Test Function

    Which function is used to define a test when using Deno’s built-in test runner?

    1. Deno.test
    2. runTest
    3. describe
    4. testIt

    Explanation: Deno.test is the correct function for defining a test in Deno's built-in test runner. runTest and testIt are not recognized functions in this system, though they may appear in other environments. describe is typically used for grouping tests in some frameworks, but not as a test-defining function in this context.

  2. Naming Tests for Clarity

    When creating a test in Deno, how should you provide the name or description of the test?

    1. As the first argument string in Deno.test
    2. By naming the file descriptively
    3. By adding a comment above the test
    4. Using an external doc file

    Explanation: The test's name or description should be passed as the first argument string to Deno.test. Comments above the test do not serve as identifiers for the test runner. Using an external doc file or only naming the file does not inform the test runner of the test’s intent.

  3. Asserting Values in Deno Tests

    Which function can be used for simple value comparison assertions in a Deno test?

    1. validateEqual
    2. assertSame
    3. matchEqual
    4. assertEquals

    Explanation: assertEquals is the correct function for checking if two values are equal in Deno tests. assertSame, matchEqual, and validateEqual are not valid assertion functions recognized by Deno's built-in tools, making them incorrect choices.

  4. Locating Test Files by Default

    How does Deno’s test runner typically identify which files to run as test files?

    1. Files ending with _test.ts or .test.ts
    2. All files in the src directory
    3. Only files named 'test.js'
    4. Files with a main function

    Explanation: By default, Deno’s test runner looks for files ending with _test.ts or .test.ts. Scanning all files in the src directory is not standard behavior. Only searching for files named 'test.js' or requiring a main function does not align with Deno's conventions.

  5. Running Tests with a Command

    Which command should you use to run all tests in a Deno project?

    1. deno execute
    2. deno run
    3. deno check
    4. deno test

    Explanation: The deno test command is specifically designed to execute all detected test files. deno run is used to run scripts but not specifically for testing. deno check is for type checking, and deno execute is not a recognized command.

  6. Asynchronous Testing Support

    What feature does Deno’s test runner provide to support tests using asynchronous code, such as awaiting a fetch call?

    1. Supports async functions as test bodies
    2. Tests must be synchronous
    3. Asynchronous code cannot be tested
    4. Requires a callback parameter

    Explanation: Deno's test runner allows test functions to be async, enabling the direct use of await within tests. Tests do not need to be strictly synchronous, nor do they require a callback pattern. It's incorrect to say asynchronous code cannot be tested.

  7. Using Assertions from the Standard Library

    Where are commonly used assertion functions like assert and assertEquals found for Deno tests?

    1. Available only through third-party modules
    2. Automatically imported in every test
    3. Built into the global Deno object
    4. Available from an official standard library module

    Explanation: Assertion functions are provided via an official standard library, which must be explicitly imported into each test file. They are not part of the global Deno object nor automatically available in every test. Third-party modules are not necessary for basic assertions.

  8. Grouping Related Tests

    How can you logically group related tests together in Deno's testing system for better organization?

    1. Prefix test names with a shared label
    2. Wrap tests in a group function
    3. Name test files with the .group.ts suffix
    4. Nest Deno.test calls inside each other

    Explanation: The common practice is to prefix related test names so they appear grouped in test output. There is no group function or built-in way to nest Deno.test calls. The file name suffix .group.ts is not recognized for grouping tests.

  9. Test Runner Output for Failed Tests

    What information does Deno's test runner display if a test fails?

    1. Just the filename
    2. Test name and a detailed error message
    3. Only the number of failed tests
    4. No output for failed tests

    Explanation: The runner provides the name of each failed test along with a clear error message to help identify issues. Displaying only the number of failed tests or just the filename is not sufficiently informative. It is incorrect to say no output is given for failed tests.

  10. Filtering Tests by Name

    How can you run only tests with names matching a specific pattern using Deno’s built-in test runner?

    1. Rename test files to 'only.ts'
    2. Edit other tests out of the files
    3. Use deno test --filter
    4. Change the default directory

    Explanation: The --filter flag allows you to target test names matching a specified pattern, running only those tests. Manually editing out other tests or renaming files is inefficient and not required. Changing the default directory does not filter test names.