我有以下内容:
@request.env['RAW_POST_DATA'] = data
@request.env['CONTENT_TYPE'] = 'application/xml'
@request.env['HTTP_CONTENT_TYPE'] = 'application/xml'
post "create", :api_key => api_key, :format => "xml"
Run Code Online (Sandbox Code Playgroud)
test.log 显示了这一点:
Processing ****Controller#create to xml (for 0.0.0.0 at 2011-07-08 15:40:20) [POST]
Parameters: {"format"=>"xml", "action"=>"create", "api_key"=>"the_hatter_wants_to_have_tea1", "controller"=>"****"}
Run Code Online (Sandbox Code Playgroud)
哪个...我想没问题,但是 RAW_POST_DATA 不会在日志中的参数列表中显示为散列...现在...当我使用curl 从终端调用操作时它可以工作:
curl -H 'Content-Type: application/xml' -d '<object><name>Das Object</name></object>' http://notAvailableDuringTesting.butWorksInDevelopmentMode.dev/object.xml?api_key=the_hatter_wants_to_have_tea1
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
在其他一些测试框架中,我习惯于标记测试,例如@really_slow、@front_end
然后运行不同批次的测试,就像我可能想要设置一个构建从站来运行所有 real_slow 测试,并且可能想要运行标记为前端的所有测试,但没有一个被标记为非常慢。
目前,要在 grails 中运行 spock+geb 测试,我只需运行 grails test-app function:
我如何告诉它运行一个子集?
我有大约 30 个用于 GET、POST、PUT、DELETE 的 REST 端点。为了测试它们的稳定性和功能,我想测试无效请求:
他们是一个框架,我可以在其中指定端点的行为(HTTP 方法、请求数据的格式、响应数据的格式)并自动生成测试数据甚至测试数据?
我很难弄清楚如何在我的 realease 管道上正确配置功能测试。我有一个解决方案,其中包含一些使用 VSTS 中的默认构建配置构建的 Web 项目。工件没问题,我可以使用发布管道发布它们。到目前为止一切顺利,现在我想使用 CodedUI 实现功能测试并将它们集成到我的版本中。我们有一个带有 vsagent 的开发服务器,它是在我配置部署组时安装的。然后我使用我在此处下载的工具手动安装了 vstest 代理。
然后我在我的发布管道上添加了一个新任务:VsTest 配置如下
这是我的发布管道中测试任务的日志输出,其中表示未找到测试程序集:
我的构建任务:
这是我的工件包,它似乎没有任何测试程序集,只有 Web 项目:
所以基本上,我如何发布我的测试程序集以便在我的发布管道中使用它们?我是否正确地将测试程序集与我的 Web 项目工件打包在一起?
functional-testing coded-ui-tests azure-devops azure-pipelines azure-pipelines-release-pipeline
我需要在 Symfony 4 中对订阅者进行功能测试,但我在寻找方法时遇到了问题。订阅者具有以下结构
/**
* Class ItemSubscriber
*/
class ItemSubscriber implements EventSubscriberInterface
{
/**
* @var CommandBus
*/
protected $commandBus;
/**
* Subscriber constructor.
*
* @param CommandBus $commandBus
*/
public function __construct(CommandBus $commandBus)
{
$this->commandBus = $commandBus;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
CommandFailedEvent::NAME => 'onCommandFailedEvent',
];
}
/**
* @param CommandFailedEvent $event
*
* @throws Exception
*/
public function onCommandFailedEvent(CommandFailedEvent $event)
{
$item = $event->getItem();
$this->processFailed($item);
}
/**
* Sends message …Run Code Online (Sandbox Code Playgroud) 我正在针对基本 API 编写功能(而非单元)测试,如下所示:
from decouple import config
from rest_framework.test import APIClient, APITestCase
class ObjectAPIResponseTest(APITestCase):
base_url = 'http://localhost:8000/api/objects/'
token = config('LOCAL_API_TOKEN') # token stored in local .env file
authenticated_client = APIClient()
def setUp(self):
self.authenticated_client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
def test_list_object_reaches_api(self):
real_response = self.authenticated_client.get(self.base_url)
self.assertEqual(real_response.status_code, 200)
self.assertEqual(real_response.headers['content-type'], 'application/json')
Run Code Online (Sandbox Code Playgroud)
测试失败:AssertionError: 401 != 200
使用curl成功测试请求后,我决定尝试requests使用Authorization标头加载,而不是使用Django REST Framework的APIClient:
import requests
from decouple import config
from rest_framework.test import APIClient, APITestCase
class ObjectAPIResponseTest(APITestCase):
base_url = 'http://localhost:8000/api/objects/'
token = config('LOCAL_API_TOKEN') # token …Run Code Online (Sandbox Code Playgroud) python django functional-testing django-testing django-rest-framework
这是我的 symfony 项目,我正在其中练习功能测试,当我测试我的功能时出现这样的错误。
在这里,发生我的错误的代码部分:\
<?php
namespace App\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use App\Entity\Category;
class AdminControllerCategoriesTest extends WebTestCase
{
public function setUp():void
{
parent::setUp();
$this->client = static::createClient();
$this->entityManager = $this->client->getContainer()->get('doctrine.orm.entity_manager');
$this->entityManager->beginTransaction();
$this->entityManager->getConnection()->setAutoCommit(false);
}
public function tearDown():void
{
parent::tearDown();
$this->entityManager->rollback();
$this->entityManager->close();
$this->entityManager = null; //avoid memory leaks
}
public function testTextOnPage()
{
$crawler = $this->client->request('GET', '/admin/categories');
$this->assertSame('Categories list', $crawler->filter('h2')->text());
$this->assertContains('Electronics', $this->client->getResponse()->getContent());
}
public function testNumberOfItems()
{
$crawler = $this->client->request('GET', '/admin/categories');
$this->assertCount(21, $crawler->filter('option'));
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我的 .env,我有数据库连接:
# In all environments, the following files are …Run Code Online (Sandbox Code Playgroud) 当您通过浏览器使用该应用程序时,您发送了一个错误的值,系统会检查表单中的错误,如果出现问题(在本例中就是这样),它会重定向一条默认错误消息,该消息写在有罪的错误消息下方场地。
这是我试图用我的测试用例断言的行为,但我遇到了我没有预料到的 \InvalidArgumentException 。
我将 symfony/phpunit-bridge 与 phpunit/phpunit v8.5.23 和 symfony/dom-crawler v5.3.7 一起使用。这是它的示例:
public function testPayloadNotRespectingFieldLimits(): void
{
$client = static::createClient();
/** @var SomeRepository $repo */
$repo = self::getContainer()->get(SomeRepository::class);
$countEntries = $repo->count([]);
$crawler = $client->request(
'GET',
'/route/to/form/add'
);
$this->assertResponseIsSuccessful(); // Goes ok.
$form = $crawler->filter('[type=submit]')->form(); // It does retrieve my form node.
// This is where it's not working.
$form->setValues([
'some[name]' => 'Someokvalue',
'some[color]' => 'SomeNOTOKValue', // It is a ChoiceType with limited values, where 'SomeNOTOKValue' does not belong. This …Run Code Online (Sandbox Code Playgroud) 我正在尝试为必须在https上运行的操作编写功能测试.我没有测试HTTPS重定向 - 我已经知道它可以在另一个测试中运行.
我想要做的是:
get :new, :protocol => "https://"
assert_redirected_to :root
Run Code Online (Sandbox Code Playgroud)
但这不会通过https发出请求.是否有"get"选项可以让我更改协议?
此外,如果我尝试指定url(例如:get"https:/test.host/do/something"),我会收到路由错误,因为我的rails级别没有用于https的路由 - 它在我的网站上处理服务器级别.