我目前正在建设一个网址缩写使用烧瓶。我觉得为应用程序编写代码相当舒服,然而,我在弄清楚如何编写测试时遇到了一些困难。你知道吗
应用程序的MVP有两个功能:
(1)给定文章中的长url,返回短url
(2)给定get中的短url,重定向到目标
我的一般代码结构如下
url_shortener
url_shortener
controller.py
setup.sh # sets up virtual env, installs requirements, creates database if it doesn't exist, spins up application
lib/ # contains functionality to shorten urls
tests/ # Unit, integration, etc tests
从我所读到的内容来看,我想为我的每个单元测试设置一个新的数据库实例。例如,假设我想测试第一个长url->;短url转换是否产生了http://myendpointurl/0。如果我使用应用程序的“真实”数据库(如果数据库中已经有任何内容),这将不起作用。从概念上讲,我理解我需要做什么,但是,我对如何将其放入代码中感到困惑。你知道吗
我试着四处寻找一些例子,但是在寻找那些没有很多新的和不熟悉的技术的例子时遇到了困难(例如:https://github.com/cgil/shortener-我没有使用fab文件、alembic、nose for testing(我使用py.试验)等)或带有测试(例如:https://github.com/richyvk/flask-url-shortener)。你知道吗
看网址缩写可能是错误的地方。相反,研究设置测试数据库和模拟数据库操作的一般技术。例如,this blog post about integration testing databases in Python和Pythonunitest.mock库。你知道吗
相关问题 更多 >
编程相关推荐