6 Replies Latest reply on Dec 10, 2008 6:13 AM by Ronald van Kuijk

    Test Driven Process Development conveniences

    Ronald van Kuijk Master

      More and more, I'm becomming a fan of this. But my tests quickly become unreadable by anyone that is not kind of familiar with some jBPM internals/api things.

      I therefore started to create more and more convenience methods in an class that extended AbstractDBTestcase. Things like deploying processes (to prevent things Bernd ran into), testing if tasks exist, are assigned to a specific actor, a specific number of tasks exist etc... all in the context of a processinstance.

      Things I came up with until now are

      For each method in the class under test:
      - Deploy a processdefinition that has the same filename and name as the method itself
      - If not exists deploy a process that has the same filename and name as the class under test
      - Start an instance of it and make sure it is running and usable
      - At the end, clean up all the 'leftovers'

      When working with a processinstance I have the following assertion methods:
      - assertTaskExists(String taskname)
      - assertTaskExistsForActor(String taskname, String expectedActorId)
      - assertTaskListLength(int expectedTasklistLength)
      - assertTaskHasEnded(String taskname)
      - assertProcessHasEnded()
      - assertVariableValue(String variableName, Object expectedValue)
      - assertNodeActive(String nodeName)

      To prevent the need to use more low level jBPM classes, I choose to use strings. Methods that do use them could ofcourse be introduced as well.

      Additional convenience methods that might be in the api eventually are:
      - endTask(String taskName);
      - endTask(String taskName, String transition);
      - assignTask(String taskName, String actorId);
      - unassignTask(String taskName); // same as assignTask with actorId being null or empty string
      - setVariable(String variableName, Object variableValue)

      More methods could be added, but these are the ones I encountered most. I'm currently cleaning up my class before posting it on my blog but hope to get some feedback in advance about this. I also want to add it to the jBPM codebase since it makes tests a lot more easier to read.