Giter Site home page Giter Site logo

Comments (4)

seancorfield avatar seancorfield commented on May 28, 2024

The function is foo, the test for foo is foo-test. That's pretty consistent.

Whilst it is true there is no need to follow any specific naming code for tests, encouraging folks to write a dedicated test for each function f, named f-test, encourages single-purpose tests: each test will exercise a specific, related function. This also allows for the source ns to be referred in (via :refer :all) without test names conflicting with the functions being tested -- although my personal preference is to :require the source ns :as sut for system-under-test.

Note that some test runners assume that tests are in namespaces with a -test suffix (i.e., in <the.ns>_test.clj), so there's an adjacent precedent for -test suffices also carrying across to the test functions themselves.

from clojure-style-guide.

Tillaert avatar Tillaert commented on May 28, 2024

I think you are confusing tradition with consistency. Consistency is: All things are post-fixed with the thing they are. Tradition is: some things are post-fixed others are not, because we always have done it that way, and we still do this even when there is no reason to do this.

Furthermore, the test foo might not test a function foo. It might be (deftest make-sure-all-dishes-are-in-loaded-in-the-dishwasher ...), which tests a specific user scenario. Postfixing test here creates the situation where you repeat the word test. This is undesired from a human language point of view. (The same reason we do not always put the word -function afther a function.)

With testing and is we have multiple tests in a single deftest, so to describe what it is, you should postfix the name of a deftest with -tests.

It is true that in the case where the test file does a :refer :all, this allows to distinguish between the function and the test, but nothing is preventing you in that case to add -test. I agree that :as sut is better, since it is short and very distinctive.

The point I want to make is that it should not be 'mandatory' to always postfix test functions with -test, as there is no technical reason to do this. If the name is decriptive and unique, there should be no reason to add anything.

(I am not talking about namespace naming, as you correctly pointed out, there is a technical reason.)

from clojure-style-guide.

danielcompton avatar danielcompton commented on May 28, 2024

However, there is no need postfix testnames with -test, since the tests are marked in their meta-data, and the test runner can locate them this way. Clojure does not locate tests by name, such as is the case in Python and Javascript, for example, where this is required.

Tests should have a different name from the function that they are testing, if only for the reason that deftest defines a function with the name of the test. You can wind up in very strange situations when you call the test instead of the function accidentally. Having a style guide rule that all tests are suffixed with -test helps avoid this, and also gives a pleasing symmetry between functions and their tests.

The point I want to make is that it should not be 'mandatory' to always postfix test functions with -test, as there is no technical reason to do this. If the name is decriptive and unique, there should be no reason to add anything.

These guidelines are part of the Clojure style guide, which documents generally accepted practices and conventions in the Clojure community. As far as I can tell, the currently documented policies match the community consensus. If you don't like them, you don't have to use them though.

See the note about consistency which acknowledges that you should still use your best judgement. If your best judgement is to not use -test, then feel free to do that. I don't think that it would be a great offence to name a test without a -test suffix if the test had a very long and descriptive name.

from clojure-style-guide.

Tillaert avatar Tillaert commented on May 28, 2024

I agree with you, however, often best judgement is cudgeled by a 'the styleguide says'.

Of course, we should give different things different names, to avoid name clashes, but that is not limited to tests. Scoping issues also happen in a let, and we do not have a mandatory postfix there.

Currently the styleguide says:

;; good
(deftest something-test ...)

;; bad
(deftest something-tests ...)
(deftest test-something ...)
(deftest something ...)

So why is there this hard distinction for tests, but not for other items that can cause scoping issues?

from clojure-style-guide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.