Drools testing with junit

前端 未结 5 1396
盖世英雄少女心
盖世英雄少女心 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:39

    I created simple library that helps to write unit tests for Drools. One of the features is exactly what you need: declare particular drl files you want to use for your unit test:

    @RunWith(DroolsJUnitRunner.class)
    @DroolsFiles(value = "helloworld.drl", location = "/drl/")
    public class AppTest {
    
        @DroolsSession
        StatefulSession session;
    
        @Test
        public void should_set_discount() {
            Purchase purchase = new Purchase(new Customer(17));
    
            session.insert(purchase);
            session.fireAllRules();
    
            assertTrue(purchase.getTicket().hasDiscount());
        }
    }
    

    For more details have a look on blog post: https://web.archive.org/web/20140612080518/http://maciejwalkowiak.pl/blog/2013/11/24/jboss-drools-unit-testing-with-junit-drools/

提交回复
热议问题