2 ms·
It seems like the obvious thing is to allow both tests in the source file and separate test file. I like the idea of short functions with doctest-like tests, b
by chubot 10y ago
It seems like the obvious thing is to allow both tests in the source file and separate test file.
I like the idea of short functions with doctest-like tests, but written with the real language, syntax-highlighted, etc. In addition to education, it's good for quick prototyping. It's also nice to see at a glance which functions don't have tests!
But I can also see it getting a bit unwieldy for complicated stuff, so in that case you can put it in another file, perhaps with a pointer.
I'm guessing you can't stop people from writing tests in separate files, so I suppose Pyret allows that.
I guess you could write a unit test framework in Python that does this with a tiny amount of metaprogramming.
def Foo():
return 5
def testFoo(t):
t.assertEqual(Foo(), 5)
So you could just look for all the functions in the file named "testFoo" where Foo is also a function, and then run them with the "t" param. Hm.
- qznc 10y agoIn Python nose can do that for you: http://nose.readthedocs.io/en/latest/ http://nose.readthedocs.io/en/latest/ In D there is even a keyword for that. It allows to embed the tests into the documentation as examples. This has the nice side effect that your examples are actually tested. https://dlang.org/spec/unittest.html https://dlang.org/spec/unittest.html