我公司的人员认为单元测试是一项额外的工作,与现有的功能测试相比,它的优势更少.单元和集成测试值得吗?请注意,未考虑测试而设计的大型现有代码库.
testing integration-testing scrum unit-testing functional-testing
我是使用Robotium在Android上测试的新手.在运行某些测试之前,我如何以编程方式卸载然后安装应用程序?
例如,为了让我测试登录活动,我需要确保不会从先前运行的应用程序中保存登录凭据.或者还有另一种方法吗?
在F#中,我想对具有多级嵌套函数的函数执行单元测试.我希望能够单独测试嵌套函数,但我不知道如何调用它们.在调试时,这些嵌套函数中的每一个都被调用为一种函数对象,但我不知道是否可以在编译时访问它们.
我不想改变我正在使用的嵌套方案,因为它在功能上最有意义地使它们以这种方式嵌套,因为在每个嵌套级别存在一些事实上的"继承"某些函数参数.
这样的事情可能吗?如果没有,单元测试嵌套函数的一般过程是什么?他们是否使用额外的参数进行单独测试,然后插入其嵌套位置后再也无法再进行测试?
非常小的例子:
let range a b =
let lower = ceil a |> int
let upper = floor b |> int
if lower > upper then
Seq.empty
else
seq{ for i in lower..upper -> i}
Run Code Online (Sandbox Code Playgroud)
如何在不改变代码的嵌套特性的情况下测试lower或upper正常工作?
我是一名开发人员,暂时负责帮助 QA 团队使用 JUnit 4 和 Selenium WebDriver 进行测试自动化。我是测试和测试自动化的新手。
查看各种 WebDriver 示例,常见的模式是在 @Before 方法中实例化 WebDriver(如 FirefoxWebDriver)的实现,在 @Test 方法中使用实例与浏览器交互,并在 @After 中使用 driver.quit() 。
因此,如果有 5 个 @Test 方法,则会打开浏览器、初始化测试应用程序并关闭浏览器 5 次。
我的问题是为什么每个测试用例都需要打开、初始化和关闭?我的猜测是为了防止一个测试用例失败对其他测试产生负面影响。它是否正确?还有其他原因吗?
我正在对我的代码进行一些测试,但我得到了第一个“停止”,因为我不知道如何继续前进。在我的函数中看到setUp()我加载装置:
public function setUp() {
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager();
$this->user = $this->createUser();
$fix = new MetaDetailGroupFixtures();
$fix->load($this->em);
parent::setUp();
}
Run Code Online (Sandbox Code Playgroud)
但后来我删除了创建的数据,因为我对坏情况进行了测试(当不返回实体时):
public function testListMetaDetailGroupFailAction() {
$client = static::createClient();
$this->logIn($client, $this->user);
$route = $client->getContainer()->get('router')->generate('meta-detail-group-list', array('parent_id' => 20000), false);
$client->request("GET", $route);
$decoded = json_decode($client->getResponse()->getContent(), true);
$this->assertCount(0, $decoded['entities']);
$this->assertArrayHasKey('success', $decoded);
$this->assertJsonStringEqualsJsonString(json_encode(array("success" => false, "message" => "No existen grupos de metadetalles de productos creados")), $client->getResponse()->getContent());
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$this->assertNotEmpty($client->getResponse()->getContent());
}
Run Code Online (Sandbox Code Playgroud)
由于记录是在安装程序中创建的,并且它们保留在数据库中,因此测试失败。对此有什么建议吗?你的是怎么解决的?
这不是问题,而是我找到的解决方案。
我正在使用 Ruby on Rails 4.1 开发一个应用程序,该应用程序以西班牙语、英语和日语显示文本。
当我开始功能测试时,我不断收到以下错误:
NoMethodError: nil:NilClass 的未定义方法“扫描”
冲浪我看到几个帖子有同样的错误,但没有一个对我有用。
这是代码原始代码:
application_controller.rb :
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
navegador = extract_locale_from_accept_language_header
ruta = params[:locale] || nil
unless ruta.blank?
I18n.locale = ruta if IDIOMAS.flatten.include? ruta
else
I18n.locale = navegador if IDIOMAS.flatten.include? navegador
end
end
private
def extract_locale_from_accept_language_header
request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
end
def ajusta_pagina_filtro
if defined? params[:post][:filtrar_por]
buscar = params[:post][:filtrar_por]
else
buscar = ''
end
page = params[:pagina] || 1
[page, …Run Code Online (Sandbox Code Playgroud) 为了测试,我将 Rack::Request 直接发送到应用程序,而不是使用服务器。
def request_via_API( app, method, path, params={} ) # app should be API
env = Rack::MockRequest.env_for( path, {:method => method, :params=>params} )
app.handle Rack::Request.new(env)
end
Run Code Online (Sandbox Code Playgroud)
非常适合测试直接输入,但我被文件上传所困扰。我的真实系统通过文件上传在浏览器中运行良好。但是现在我想通过 API 对其进行测试,并且不知道如何通过任何 Rack 类/方法将文件内容放入请求中。(我尝试理解 Rack::Test::UploadedFile 但没有成功)。
谢谢,阿利斯泰尔
我正在用 symfony2 进行一些功能测试。我想选择一个基本形式的单选按钮:
<form method="post" action="mylink">
<input id="position_51" type="radio" name="user_position" value="51">
<input id="position_52" type="radio" name="user_position" value="52">
<input id="position_54" type="radio" name="user_position" value="54">
<input id="position_57" type="radio" name="user_position" value="57">
<button id="bt_submit" type="submit">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
所以我选择表格
$buttonFrom = $client->getCrawler()->selectButton('bt_submit');
$form = $buttonFrom->form();
Run Code Online (Sandbox Code Playgroud)
现在,如果我想选择具有特定 ID(例如“position_54”)的收音机并勾选它。怎么做?在我发现的所有示例中,tick() 似乎用于输入的 name 属性......这在单选按钮案例中对我没有帮助。
$form['user_position'] 似乎不是一个数组...
谢谢
为了针对前端运行功能测试,我们正在考虑模拟我们的后端。不过,我们的后端迭代速度非常快并且变化很大。所以嘲笑它意味着我们总是需要知道所有的变化并相应地更新我们的模拟。
我想知道是否可以自动化这个过程。
这是我的 phpunit.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true"
strict="true"
bootstrap="./vendor/autoload.php">
<testsuites>
<php>
<server name="KERNEL_DIR" value="app" />
<ini name="display_errors" value="true"/>
</php>
<testsuite name="Functional Tests">
<directory>./tests/src/myApp/AppBundle/functional</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
Run Code Online (Sandbox Code Playgroud)
这是测试类
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MyTest extends WebTestCase
{
private $client;
public function setUp()
{
$this->client = static::createClient();
}
Run Code Online (Sandbox Code Playgroud)
运行测试时,我得到了 setUp 中的一行:
根据https://symfony.com/doc/current/book/testing.html#your-first-functional-test在 phpunit.xml 中设置 KERNEL_DIR 或覆盖 WebTestCase::createKernel() 方法