[Python] Use Python to generate Java Unit Test codes automatically
来源:互联网 发布:手机听英语单词软件 编辑:程序博客网 时间:2024/05/17 00:56
This code snippet is used to generate the unit test of Java codes.
import osimport stringdef task(source,target): files = os.listdir(source) target_files = {} for source_file in files: if source_file.endswith('.java'): file_list = source_file.split('.') new_file = file_list[0]+'Test.java' new_class = file_list[0]+'Test' target_files.update({new_class:new_file}) for new_class,target_file in target_files.items(): absolute_file = target + target_file file_stream = open(absolute_file,'a') code_template = ''' public class $class { @Test public void test$source(){ } } ''' t = string.Template(code_template) file_stream.write(t.substitute({'class':new_class,'source':new_class.strip('Test')})); file_stream.close() if __name__ == '__main__': print 'The task starts' source_directory = 'F:\eclipse\workspace\ZenJava\src\main\java\com\wonderfan\\' target_directory = 'F:\eclipse\workspace\ZenJava\src\test\java\com\wonderfan\\' task(source_directory,target_directory) print 'The task is over'
0 0
- [Python] Use Python to generate Java Unit Test codes automatically
- Use python for C++ unit/function test
- How to use bindings-generator to generate lua binding automatically
- Python---unit test
- Use mdev to automatically generate the device node
- python unit test to assert a method calls sys.exit()
- [Python] Do your unit test to ensure code's quality
- Python 中的 unit test 流程
- Use Python to run REST API Automation Test
- Python:使用suite执行unit-test用例
- python如何使用unit test 模块
- Using Mockito to Unit Test Java Applications
- use python to sendmail
- Use Python to plot
- use python to sendmail
- use python to sendmail
- How to generate attribute sets automatically?
- Design to Unit Test
- 一个简单的REST服务实例
- 严重: Servlet.service() for servlet jsp threw exception
- C#动态加载树菜单
- POJ 1990 MooFest(树状数组+离线处理)
- 第二次编程作业:判断一个正整数是否为质数的算法和 随机生成一个n bit位的长整数
- [Python] Use Python to generate Java Unit Test codes automatically
- 变形课
- 计算机视觉、机器学习相关领域论文和源代码大集合--持续更新……
- 九度OJ 1527 首尾相连数组的最大子数组和
- javascript小技巧
- php实现限制文件下载速度的代码实例
- 29.特殊的数字
- 指定jquery文本框的时间格式
- 的人和他的计划统计统计太费劲