Skip to content

Custom system of unit testing not always run created tests #230

Closed

Description

@GegznaV

Unit tests in some files were not attached correctly. This resulted in not running tests or at least not including the results in test coverage reports. One of the examples how it was fixed is in 36bc22e. This issue occurs in methods that are not actual functions defined as (see below) in hyperSpec:

some_function <- function() {
 # function body
}

@cbeleites

  1. Is there a mechanism that automatically warns if some tests are created in a file but not used properly by e.g. CI system or code coverage tools?
  2. I expect a section on this to be included in the documentation of hySpc.testthat.

P.S: I write this issue in cbeleites/hyperSpec, as it uses a bit different version of unit testing than it is implemented in hySpc.testthat.

Activity

  1. added
    Type: bug 💣
    Topic: unit test 1️⃣
    on Jul 26, 2020
  2. bryanhanson commented on Jul 26, 2020

    @bryanhanson
    Collaborator

    I'll just put this here since I've not raised it before, but there is a package, roxut that allows one to write the unit tests in the body of the function definition, and simply captures those unit tests and writes them to the appropriate test file (works with testthat and tinytest). Inspired by @cbeleites approach but a simpler implementation. How do I know this? I authored it about a month ago.

    Not suggesting hyperSpec series switch, just bringing it to everyone's attention. There is also, I found out after I completed my work, another package called roxytest which does the same thing and does a few other things that are nice additions to roxygen2.

  3. cbeleites commented on Jul 29, 2020

    @cbeleites
    Owner

    Here is what I think happens:

    • there are still quite a lot of calls to setMethod() in hyperSpec that use anonymous functions.
    • in that case, test(method) <- function() {...} may attach the test to a generic which is not in the hyperSpec:: namespace.
    • the unit testing mechanism for attached tests (both as currently in hyperSpec and in hySpc.testtat) collects and runs only unit tests in namespace hyperSpec::.

    Empty placeholder functions are IMHO misleading. But properly moving the functionality into a hidden internal function and attaching the test to that function both solves this issue and makes debugging easier (#238).

  4. GegznaV commented on Jul 29, 2020

    @GegznaV
    CollaboratorAuthor

    Empty placeholder functions are IMHO misleading.

    Fixed in #225

    Here is what I think happens:

    In some situations, R doesn't allow building the package is a test is attached to a wrong function (i.e., it is not possible to attach test to some random name. But the issue is when there is no error but the test still does not work as expected. A big number of skip messages even worsens the ability to identify discrepancies.

  5. cbeleites commented on Aug 28, 2020

    @cbeleites
    Owner

    @GegznaV is this solved by now? If so, please close. If not, please give further explanations. Thank you.

  6. GegznaV commented on Aug 31, 2020

    @GegznaV
    CollaboratorAuthor

    I do not think it is solved if tests can get attached to a wrong namespace without warning.

    In some cases, there were warnings/errors that the test could not be attached to a function (and I liked that). But it is confusing that for some functions this is not the case.

  7. GegznaV commented on Feb 16, 2021

    @GegznaV
    CollaboratorAuthor

    I do not think this is solved in the sense I imagine it should be solved. Yet now it is more clear for me, how the tests should be attached to S4 methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Topic: unit test 1️⃣Type: bug 💣

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions