I'm toying with the idea of a new way to write tests. This is a cross between state and interaction based testing, and also tries to make setting up the test environments easier. I call it "Flow Testing" as it tests how the various states of the test target flow from one to the next.
The idea is several-fold. We begin on the idea that we are testing names, because everything in Python starts with a name. You will test different things about names, such as type, what attributes or other properties apply to certain conditions, etc.
Flow testing is very tree-oriented. For every name, you define the state you expect to begin, and branch into the state you expect for various properties. For example, you may have a state for the name 'foo' and a branch state for 'foo.bar'. These are branches within one state, while wthere are other branches across states called Interaction Branches. These states define the interactions that lead to them and the states expected.
The example below defines a test for a simple module that should have a simple function. It defines that the name foo should be a module and that the state of its 'bar' attribute should be a callable. It then defines the state of a call to bar, and details it under more specific conditions of the interaction (specific arguments given).
The idea is several-fold. We begin on the idea that we are testing names, because everything in Python starts with a name. You will test different things about names, such as type, what attributes or other properties apply to certain conditions, etc.
Flow testing is very tree-oriented. For every name, you define the state you expect to begin, and branch into the state you expect for various properties. For example, you may have a state for the name 'foo' and a branch state for 'foo.bar'. These are branches within one state, while wthere are other branches across states called Interaction Branches. These states define the interactions that lead to them and the states expected.
The example below defines a test for a simple module that should have a simple function. It defines that the name foo should be a module and that the state of its 'bar' attribute should be a callable. It then defines the state of a call to bar, and details it under more specific conditions of the interaction (specific arguments given).
This is just an idea, and does not work or exist yet. Any comments? If it seems solid, I'd like to start working on it.
import flowtest
import foo
class test_foo(flowtest.State):
targetType = flowtest.module
targetHasAttributes = ('bar',)
class test_bar(flowtest.State):
targetType = flowtest.callable
class testReturn(flowtest.State):
targetType = basestring
class testReturn(flowtest.State):
flowtest.callArguments()
flowtest.callArguments('hi')
targetContains = u"hello"
class testReturn(flowtest.State):
flowtest.callArguments('bye')
targetType = basestring
targetContains = u"goodbye"
Comments
Also, the string "flowstate." is in there way too many times IMO to be an easy-to-use API. :/ Wouldn't it be cleaner if most of those were replaced with "self." (since you're already subclassing flowstate.State, etc.)?