Dolphinscheduler: [Improve][ut]Refactor SqlExecutorTest

Created on 8 Dec 2020  ·  5Comments  ·  Source: apache/dolphinscheduler

运行 SqlExecutorTest 测试类的时候报错,应该是没有拉起spring 服务,请问是缺少了什么注解吗?
WechatIMG1260

Most helpful comment

Please use english!!!
and you can write the test like this before you configured correctly

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={DependencyConfig.class, SpringApplicationContext.class, SpringZKServer.class,
        NettyExecutorManager.class, ExecutorDispatcher.class, ZookeeperRegistryCenter.class, TaskPriorityQueueConsumer.class,
        ZookeeperNodeManager.class, ZookeeperCachedOperator.class, ZookeeperConfig.class, MasterConfig.class})
public class MyTest {

    @Autowired
    private ProcessService processService = null;

    @Test
    public void test01(){
        System.out.println(processService);
    }
}

recommended the mock , you can write the test like this

@RunWith(MockitoJUnitRunner.Silent.class)
public class MyTestMock {
    @Autowired
    private ProcessService processService = null;
    @Before
    public void init(){
        processService = mock(ProcessService.class);
    }
    @Test
    public void test01(){
        System.out.println(">>>>>>>>>>>>>" + processService.getUserById(1));
    }
}

All 5 comments

This UT is marked with @Ignore. If you are interested, you can refactor it. It is recommended to use the mock form and only test the SqlExecutor method.

Please use english!!!
and you can write the test like this before you configured correctly

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={DependencyConfig.class, SpringApplicationContext.class, SpringZKServer.class,
        NettyExecutorManager.class, ExecutorDispatcher.class, ZookeeperRegistryCenter.class, TaskPriorityQueueConsumer.class,
        ZookeeperNodeManager.class, ZookeeperCachedOperator.class, ZookeeperConfig.class, MasterConfig.class})
public class MyTest {

    @Autowired
    private ProcessService processService = null;

    @Test
    public void test01(){
        System.out.println(processService);
    }
}

recommended the mock , you can write the test like this

@RunWith(MockitoJUnitRunner.Silent.class)
public class MyTestMock {
    @Autowired
    private ProcessService processService = null;
    @Before
    public void init(){
        processService = mock(ProcessService.class);
    }
    @Test
    public void test01(){
        System.out.println(">>>>>>>>>>>>>" + processService.getUserById(1));
    }
}

Please use english!!!
and you can write the test like this before you configured correctly

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={DependencyConfig.class, SpringApplicationContext.class, SpringZKServer.class,
        NettyExecutorManager.class, ExecutorDispatcher.class, ZookeeperRegistryCenter.class, TaskPriorityQueueConsumer.class,
        ZookeeperNodeManager.class, ZookeeperCachedOperator.class, ZookeeperConfig.class, MasterConfig.class})
public class MyTest {

    @Autowired
    private ProcessService processService = null;

    @Test
    public void test01(){
        System.out.println(processService);
    }
}

We hope to adopt the mock form, because ut should remain relatively independent. Are you interested in refactoring this UT?

OK, thanks

@CalvinKirs
Sure,I can do this.

Was this page helpful?
0 / 5 - 0 ratings