Drools testing with junit

前端 未结 5 1538
盖世英雄少女心
盖世英雄少女心 2021-02-14 09:54

What is the best practice to test drools rules with junit?

Until now we used junit with dbunit to test rules. We had sample data that was put to hsqldb. We had couple of

5条回答
  •  孤城傲影
    2021-02-14 10:35

    Personally I use unit tests to test isolated rules. I don't think there is anything too wrong with it, as long as you don't fall into a false sense of security that your knowledge base is working because isolated rules are working. Testing the entire knowledge base is more important.

    You can write the isolating tests with AgendaFilter and StatelessSession

    StatelessSession session = ruleBase.newStatelessSesssion();
    
    session.setAgendaFilter( new RuleNameMatches("") );
    
    List data = new ArrayList();
    ... // create your test data here (probably built from some external file)
    
    StatelessSessionResult result == session.executeWithResults( data );
    
    // check your results here.
    

    Code source: http://blog.athico.com/2007/07/my-rules-dont-work-as-expected-what-can.html

提交回复
热议问题