我在想,如果我们是否有类似assert_no_template的的对面assert_template.
我试图测试的是实际渲染中没有使用具体模板.
我正在尝试polymorphic_path在Rails 3中使用功能测试.
起初我会得到
NoMethodError: undefined method `polymorphic_path' for #<ArticlesControllerTest:0x492f17c>
Run Code Online (Sandbox Code Playgroud)
然后我补充道
include Rails.application.routes.url_helpers
Run Code Online (Sandbox Code Playgroud)
该undefined method error停止了,但现在常规路径,如article_path(article)例如停止工作:
NameError: undefined local variable or method `default_url_options' for #<ArticlesControllerTest:0x33ccbe0>
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing'
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/routing/url_for.rb:102:in `url_options'
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/routing/url_for.rb:131:in `url_for'
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/routing/route_set.rb:195:in `article_path'
Run Code Online (Sandbox Code Playgroud)
我曾经能够通过包含在Rails 2中正常使用polymorphic_path
include ActionController::UrlWriter
Run Code Online (Sandbox Code Playgroud)
如何在Rails 3中使用它?
ruby ruby-on-rails functional-testing ruby-on-rails-3 rails-3-upgrade
我想在相同的测试中对一些获取请求进行分组,但是我得到了不稳定的行为.我有以下两个测试:
test 'index for local seller (same site)' do
seller = FactoryGirl.create :seller, business_site: @open_or.business_site
get :index, nil, {user_id: seller.to_param }
assert_select "table#order_requests tr##{@controller.view_context.dom_id @open_or}"
end
test 'index for local seller (different site)' do
seller = FactoryGirl.create :seller_local
get :index, nil, {user_id: seller.to_param }
assert_select "table#order_requests tr##{@controller.view_context.dom_id @open_or}", false
end
Run Code Online (Sandbox Code Playgroud)
我希望在一次测试中合并,但如果我这样做,第二个断言将错误地失败(预期正好0个元素匹配"table#order_requests tr#order_request_1000244799",找到1.).我真的不明白为什么?第二次'get'调用可能无法正常重置某些内容.我想方设法"重置"请求但没有成功.
我正在尝试为使用Django REST Framework编写的REST API编写一些功能测试.然而,它并不是特定于该框架,因为它主要是一般的Django.
这就是我想要做的
setUp在测试类的方法中创建用户tests.py
from django.test import LiveServerTestCase
from django.contrib.auth.models import User
from django.test.client import Client
from rest_framework.authtoken.models import Token
class TokenAuthentication(LiveServerTestCase):
def setUp(self):
user = User.objects.create(username='foo', password='password', email="foo@example.com")
user.save()
self.c = Client()
def test_get_auth_token(self):
user = User.objects.get(username="foo")
print user # this outputs foo
print Token.objects.get(user_id = user.pk) # this outputs a normal looking token
response = self.c.post("/api-token-auth/", {'username': 'foo', 'password': 'password'})
print response.status_code # this outputs 400
self.assertEqual(response.status_code, 200, "User couldn't log in")
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,它返回状态400而不是200,因此用户未经过身份验证.如果我输入已经在数据库中的用户的凭据,它会通过.所以我假设在测试类中创建的记录只能在它自己的方法中访问,这可能是因为它是为单元测试而设计的.但是我使用数据库中的数据来执行测试,如果数据发生变化,它将失败. …
django functional-testing django-testing django-rest-framework
我一直试图运行这段代码,但不知何故已经出现'单位不匹配,布尔预期错误'.我已经在Stackoverflow上遇到了各种问题,但没有找到任何具体的问题来回答我的问题.
def balance(chars: List[Char]): Boolean =
{
var i = 0;
var j = 0;
if (Count(i, j) == 0){
true
}
else{
false
}
def Count(count: Int, Pos: Int): Int =
{
if (Pos == chars.length)
{
count
}
else
{
if (chars(Pos) == '(')
{
Count(count + 1, Pos + 1);
}
else
{
Count(count - 1, Pos + 1);
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在我的应用程序上进行一些功能测试,我想我已经非常接近了.我的问题是,当我运行第一次测试时,我得到了错误.
无法连接到远程服务器.
预期:好的
但是:0
我可以确认,如果我在断言上设置断点,然后尝试BaseUrl在我的浏览器中点击,则找不到它.
这是我的考试.
[Test]
public void MyTestTest ()
{
var client = new RestClient( ServiceTestAppHostBase.BaseUrl );
// client.Authenticator = new HttpBasicAuthenticator( NUnitTestLoginName, NUnitTestLoginPassword );
var request = new RestRequest( "/users/", Method.GET );
request.RequestFormat = DataFormat.Json;
var response = client.Execute( request );
// do assertions on the response object now
Assert.That( response.StatusCode, Is.EqualTo( HttpStatusCode.OK ) );
}
Run Code Online (Sandbox Code Playgroud)
在AppServerTestSetup这个样子的
[SetUpFixture]
public class AppServerTestSetup
{
ServiceTestAppHostBase _appHost;
[SetUp]
public void SetUp()
{
_appHost = new ServiceTestAppHostBase(); …Run Code Online (Sandbox Code Playgroud) 根据我的理解,有两个主要的软件包可以帮助测试软件包--TinyTest和Velocity,后者成为官方Meteor测试框架.
从6月份Meteor的DevShop开始,Velocity团队表示Velocity可以和TinyTest一起运行,但是我不明白这两个软件包提供的功能有什么不同,一个(TinyTest)是多余的?
TinyTest仅用于单元测试吗?如果我想进行集成测试,功能测试,我是否需要转向Velocity及其支持的框架?还是别的什么完全不同?有一个比较表,但它有点过时了.
unit-testing functional-testing meteor meteor-velocity tinytest
我正在为项目的题字部分创建功能测试,如果表单需要进入ajax请求,我需要知道如何测试它,否则服务器将始终返回空的题字表单.
看起来提交方法没有采用一个参数来指定它是否是一个不像请求方法的请求的ajax - > http://api.symfony.com/2.3/Symfony/Component/HttpKernel/Client.html#method_submit
谢谢
UPDATE1
////////////////////////////////////////////////
// My functional test looks exactly like this //
////////////////////////////////////////////////
$form = $buttonCrawlerNode->form(array(
'name' => 'Fabien',
'my_form[subject]' => 'Symfony rocks!',
));
// There is no way here I can tell client to submit using ajax!!!!
$client->submit($form);
// Why can't we tell client to submit using ajax???
// Like we do here in the request méthod
$client->request(
'GET',
'/post/hello-world',
array(),
array(),
array('HTTP_X-Requested-With' => 'XMLHttpRequest')
);
Run Code Online (Sandbox Code Playgroud) 我会说三者都是一样的,但我想知道它们之间是否存在细微差别.最后,我认为您正在测试所有这些用户场景.
我正在用Jest + Puppeteer取代CasperJS.将所有内容放在一个文件中效果很好:
beforeAll(async () => {
// get `page` and `browser` instances from puppeteer
});
describe('Test A', () => {
// testing
});
describe('Test B', () => {
// testing
});
afterAll(async () => {
// close the browser
});
Run Code Online (Sandbox Code Playgroud)
现在,我真的不想将所有内容保存在一个文件中.维护更难以运行部分测试(例如,只是'测试A').
我查看了Jest文档并阅读了有关setupScript的内容.它会很完美,但它会在每个测试文件之前运行.我不想要这个,因为puppeteer设置需要花费很多时间.无论我运行多少个测试文件,我都希望重复使用相同的浏览器实例并只支付一次设置成本.
所以,我想到了:
// setup puppeteer
await require('testA')(page, browser, config);
await require('testB')(page, browser, config);
// cleanup
Run Code Online (Sandbox Code Playgroud)
这解决了模块化问题,重用了相同的浏览器实例,但不允许我单独运行测试.
最后,我偶然发现了创建自定义testEnviroment的可能性.这听起来很棒但是没有很好的文档记录,所以我甚至不确定每个测试文件是创建env实例,还是每次运行Jest.稳定的API也是一个缺少一种setup方法,我可以设置puppeteer(我必须在构造函数中执行,不能是异步).
由于我是Jest的新手,我可能会遗漏一些明显的东西.在我深入研究之前,我会问这里.
ajax ×1
c# ×1
django ×1
e2e-testing ×1
gui-testing ×1
jestjs ×1
meteor ×1
php ×1
phpunit ×1
puppeteer ×1
ruby ×1
scala ×1
servicestack ×1
symfony ×1
tinytest ×1
unit-testing ×1