我们在Django站点中有一堆命令,一些是管理命令,一些是在cron作业上运行的,我无法弄清楚如何测试.他们几乎看起来像这样:
# Saved in file /app/management/commands/some_command.py
# Usage: python manage.py some_command
from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):
def handle_noargs(self, **options):
# Do something useful
Run Code Online (Sandbox Code Playgroud)
我有一些测试,看起来像这样:
import unittest
from django.test import TestCase
from django_webtest import WebTest
class SomeTest(WebTest):
fixtures = ['testdata.json']
def setUp(self):
self.open_in_browser = False
# Set up some objects
def test_registration(self):
response = self.client.get('/register/')
self.assertEqual(response.status_code, 200)
form = self.app.get('/register/').forms[1]
# Set up the form
response = form.submit()
self.assertContains(response, 'You are Registered.')
if self.open_in_browser:
response.showbrowser()
# Here I'd like to …
Run Code Online (Sandbox Code Playgroud) 我正在使用Python和Webtest来测试WSGI应用程序.我发现处理程序代码中引发的异常往往被Webtest吞噬,然后引发泛型:
AppError: Bad response: 500 Internal Server Error
Run Code Online (Sandbox Code Playgroud)
如何告诉它引发或打印导致此错误的原始错误?
我正在尝试运行FacebookLoginTest.问题是:Symfony2客户端不发送真实的HTTP请求,因此它不适用于其他服务的URL(如facebook).
我知道我可以使用cUrl,...但我看到那里有很多障碍:session,javascript,redirects.
有什么想法我们如何才能运行?任何人都有自动oAuth测试运行?
我正在使用jest-puppeteer来运行我的网络测试.如果我运行我在一个文件中定义的测试,一切都很完美.
describe('user', () => {
jest.setTimeout(12000);
beforeEach(async () => {
await page.setViewport({width: 1200, height: 2000});
await page.goTo('http://localhost:3000');
});
it('test 1', async () => {
//my test steps
});
it('test 2', async () => {
//my test steps
});
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我在自己的文件中运行每个测试,我会收到错误.
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'addExpectationResult' of undefined
Run Code Online (Sandbox Code Playgroud)
文件1
describe('user', () => {
jest.setTimeout(12000);
beforeEach(async () => {
await page.setViewport({width: 1200, height: 2000});
await page.goTo('http://localhost:3000');
});
it('test 1', async () => {
//my test steps
});
});
Run Code Online (Sandbox Code Playgroud)
文件2
describe('user', () …
Run Code Online (Sandbox Code Playgroud) 我正在使用Microsoft WebTest,并希望能够执行类似于NUnit的操作Assert.Fail()
.我提出的最好的是,throw new webTestException()
但这在测试结果中显示为一个Error
而不是一个Failure
.
除了反映WebTest
设置私有成员变量以指示失败之外,还有一些我错过的东西吗?
编辑:我也使用了该Assert.Fail()
方法,但是当从WebTest中使用时,这仍然显示为错误而不是失败,并且该Outcome
属性是只读的(没有公共设置器).
编辑:好吧,现在我真的很难过.我使用反射将Outcome
属性设置为Failed,但测试仍然通过!
这是将Oucome设置为失败的代码:
public static class WebTestExtensions
{
public static void Fail(this WebTest test)
{
var method = test.GetType().GetMethod("set_Outcome", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(test, new object[] {Outcome.Fail});
}
}
Run Code Online (Sandbox Code Playgroud)
这是我试图失败的代码:
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
this.Fail();
yield return new WebTestRequest("http://google.com");
}
Run Code Online (Sandbox Code Playgroud)
Outcome
正在设置,Oucome.Fail
但显然WebTest框架并没有真正使用它来确定测试通过/失败结果.
我正在Visual Studio 2015中编写webtest.我目前使用的webtest允许我运行静态测试.我想把事情搞清楚,从而增加更真实的数据.我想要使用的数据存储在Oracle Database 12c中.所以我正在尝试向webtest添加一个新的数据源.我输入了我要连接的TNSName,用户名和密码并测试连接.可以建立连接,但是我可以选择的表列表是空的.
使用Visual Studio 2015中的"服务器资源管理器"连接到同一数据库.使用这种方法,我得到该数据库中包含的完整表列表.我甚至可以查询任何表格.
那么如何修复我的webtest才能访问特定的数据库表(行)?
我们有业务用户,我们想参与为我们的项目编写webtests,但为此目的购买完整的Visual Studio许可似乎有点过分.
是否有任何开源或第三方工具可用于生成可由Visual Studio读取的Web测试?
我更喜欢集成到IE或Firefox中的工具,并且可以像Visual Studio集成提供的点击方法一样生成测试.
是否有.NET的无头浏览器?
我在测试环境中寻找这个.
来自Java我想到了类似于HtmlUnit(http://htmlunit.sourceforge.net/)的东西,它本身就是Canoo WebTest或Celerity等不同高级工具的基础.
我想在.Net环境中为Web应用程序创建自动UI测试,但不使用Browser-Remoting(Watin,Selenium ...)
如果可能的话,我想坚持使用.Net解决方案并避免使用Java或Ruby工具.
有什么选择?你们在干什么?
谢谢
我正在测试我的烧瓶应用程序,它使用flask-login扩展.
我正在使用webtest设置所有我的测试:
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
self.client = webtest.TestApp(app)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试通过使用@login_required修饰的self.client.get()访问URL时,我收到401错误,并显示一条消息,表示我无权访问该URL.
根据文档https://flask-login.readthedocs.org/en/latest/#protecting-views 和本讨论,将'TESTING'的配置值设置为True应该禁用登录要求,但这似乎不是为我工作
有什么建议?
我使用symfony 3.0与phpUnit框架3.7.18
单元测试文件. abcControllerTest.php
namespace AbcBundle\Tests\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class AbcControllerTest extends WebTestCase {
public function testWithParams() {
$Params = array("params" => array("page_no" => 5));
$expectedData = $this->listData($Params);
print_r($expectedData);
}
private function listData($Params) {
$client = static::createClient();
$server = array('HTTP_CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json');
$crawler = $client->request('POST', $GLOBALS['host'] . '/abc/list', $Params,array(), $server);
$response = $client->getResponse();
$this->assertSame('text/html; charset=UTF-8', $response->headers->get('Content-Type'));
$expectedData = json_decode($response->getContent());
return $expectedData;
}
}
Run Code Online (Sandbox Code Playgroud)
行动:abc/list
abcController.php
public function listAction(Request $request) {
$Params = json_decode($request->getContent(), true); …
Run Code Online (Sandbox Code Playgroud) webtest ×10
unit-testing ×4
python ×3
testing ×3
symfony ×2
web-testing ×2
.net ×1
automation ×1
c# ×1
django ×1
e2e-testing ×1
facebook ×1
flask ×1
flask-login ×1
jestjs ×1
json ×1
mstest ×1
oauth ×1
oracle ×1
phpunit ×1
puppeteer ×1