unit-testing
Pytest – how to skip tests unless you declare an option/flag?
The pytest documentation offers a nice example on how to skip tests marked “slow” by default and only run them with a –runslow option: # conftest.py import pytest def pytest_addoption(parser): parser.addoption( “–runslow”, action=”store_true”, default=False, help=”run slow tests” ) def pytest_configure(config): config.addinivalue_line(“markers”, “slow: mark test as slow to run”) def pytest_collection_modifyitems(config, items): if config.getoption(“–runslow”): # –runslow … Read more
Supertest custom express server in node
You need to export the app object in server.js: var app = express(); module.exports = app; …
How to test enum types?
For enums, I test them only when they actually have methods in them. If it’s a pure value-only enum like your example, I’d say don’t bother. But since you’re keen on testing it, going with your second option is much better than the first. The problem with the first is that if you use an … Read more
AutoFixture.AutoMoq supply a known value for one constructor parameter
So I’m sure people could work out the generalized implementation of Mark’s suggestion but I thought I’d post it for comments. I’ve created a generic ParameterNameSpecimenBuilder based on Mark’s LifeSpanArg: public class ParameterNameSpecimenBuilder<T> : ISpecimenBuilder { private readonly string name; private readonly T value; public ParameterNameSpecimenBuilder(string name, T value) { // we don’t want a … Read more
Is there a python assert() method which checks between two boundaries?
Frédéric’s suggestion to use: self.assertTrue(3 <= myInt <= 8) results in test output like this: AssertionError: False is not True which gives the developer no clue as to what the problematic value of myInt actually was. It is better to be more long-winded: self.assertGreaterEqual(myInt, 3) self.assertLessEqual(myInt, 8) because then you get helpful test output like … Read more
running single rails unit/functional test
The following answer is based on: How to run single test from rails test suite? (stackoverflow) But very briefly, here’s the answer: ruby -I test test/functional/whatevertest.rb For a specific functional test, run: ruby -I test test/functional/whatevertest.rb -n test_should_get_index Just put underscores in places of spaces in test names (as above), or quote the title as … Read more