标签: functional-testing

Ruby on Rails:功能测试:POST 不发送原始 XML 数据

我有以下内容:

  @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)

我在这里做错了什么?

testing ruby-on-rails http-post functional-testing

5
推荐指数
1
解决办法
1485
查看次数

如何在 grails 中运行 spock 功能测试的子集?

在其他一些测试框架中,我习惯于标记测试,例如@really_slow、@front_end

然后运行不同批次的测试,就像我可能想要设置一个构建从站来运行所有 real_slow 测试,并且可能想要运行标记为前端的所有测试,但没有一个被标记为非常慢。

目前,要在 grails 中运行 spock+geb 测试,我只需运行 grails test-app function:

我如何告诉它运行一个子集?

tags grails functional-testing spock geb

5
推荐指数
1
解决办法
2204
查看次数

自动生成 REST API 测试

我有大约 30 个用于 GET、POST、PUT、DELETE 的 REST 端点。为了测试它们的稳定性和功能,我想测试无效请求:

  • 空主体(如果端点需要主体)
  • 现有正文(如果端点不需要正文)
  • 无效的正文数据(缺失值、数据类型错误的值等)
  • 请求参数数据无效
  • 无效标头

他们是一个框架,我可以在其中指定端点的行为(HTTP 方法、请求数据的格式、响应数据的格式)并自动生成测试数据甚至测试数据?

testing rest json http functional-testing

5
推荐指数
0
解决办法
1076
查看次数

测试服务是功能测试还是集成测试

我们有一个提供功能的 .Net 组件。我们有一个 Restful Web API 服务,世界将用它来调用该功能。我们编写了使用 OWIN 调用 Web API 控制器的测试。

过去,我一直将这些称为“集成测试”,因为服务是一个单独的组件。然而,另一位我尊敬的开发人员告诉我,这不是集成测试,而是“功能测试”。

我查看了功能测试的定义和集成测试的定义,对于我来说,对于 RESTful 服务测试的测试应该如何称呼,两者都不是明显的赢家。

是集成还是功能?是否有任何权威来源可以用来明确回答这个问题(因为我不希望我的问题因“征求辩论”而被关闭)?

testing integration-testing functional-testing

5
推荐指数
1
解决办法
904
查看次数

发布带有工件的测试程序集,以便在 VSTS 上的功能测试期间使用它们

我很难弄清楚如何在我的 realease 管道上正确配置功能测试。我有一个解决方案,其中包含一些使用 VSTS 中的默认构建配置构建的 Web 项目。工件没问题,我可以使用发布管道发布它们。到目前为止一切顺利,现在我想使用 CodedUI 实现功能测试并将它们集成到我的版本中。我们有一个带有 vsagent 的开发服务器,它是在我配置部署组时安装的。然后我使用我在此处下载的工具手动安装了 vstest 代理。

然后我在我的发布管道上添加了一个新任务:VsTest 配置如下

在此处输入图片说明

这是我的发布管道中测试任务的日志输出,其中表示未找到测试程序集:

在此处输入图片说明

我的构建任务:

在此处输入图片说明

这是我的工件包,它似乎没有任何测试程序集,只有 Web 项目:

在此处输入图片说明

所以基本上,我如何发布我的测试程序集以便在我的发布管道中使用它们?我是否正确地将测试程序集与我的 Web 项目工件打包在一起?

functional-testing coded-ui-tests azure-devops azure-pipelines azure-pipelines-release-pipeline

5
推荐指数
1
解决办法
4416
查看次数

Symfony 4 中的功能测试事件和订阅者

我需要在 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)

php testing events functional-testing symfony4

5
推荐指数
1
解决办法
1976
查看次数

测试 Django REST Framework 时,为什么无法使用 APIClient.credentials() 使用令牌进行身份验证?

我正在针对基本 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

5
推荐指数
1
解决办法
3392
查看次数

symfony 5 中的功能测试

这是我的 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)

php testing functional-testing symfony doctrine-orm

5
推荐指数
2
解决办法
1966
查看次数

如何使用 Symfony 爬虫组件和 PHPUnit 测试表单提交的错误值?

当您通过浏览器使用该应用程序时,您发送了一个错误的值,系统会检查表单中的错误,如果出现问题(在本例中就是这样),它会重定向一条默认错误消息,该消息写在有罪的错误消息下方场地。

这是我试图用我的测试用例断言的行为,但我遇到了我没有预料到的 \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)

php forms functional-testing symfony domcrawler

5
推荐指数
1
解决办法
913
查看次数

功能测试"获取"请求和https协议

我正在尝试为必须在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的路由 - 它在我的网站上处理服务器级别.

get ruby-on-rails functional-testing

4
推荐指数
1
解决办法
1577
查看次数