我有一个方法的符号名称,我想用一些参数调用它。我真正想做的归结为以下代码片段:
method.to_proc.call(method)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,method是对象上方法的符号名称。就我而言,我试图调用一个恰好是对象私有的方法。
这是我得到的错误输出:
>$ ruby symbol_methods.rb
symbol_methods.rb:33:in `call': private method `test_value_1' called for "value":String (NoMethodError)
from symbol_methods.rb:33:in `block (2 levels) in <main>'
from symbol_methods.rb:30:in `each'
from symbol_methods.rb:30:in `block in <main>'
from symbol_methods.rb:29:in `each'
from symbol_methods.rb:29:in `<main>'
Run Code Online (Sandbox Code Playgroud)
这是一个演示此行为的自包含示例:
data = [
["value", true],
["any value here", true],
["Value", true],
]
def matches_value(string)
string == "value"
end
def contains_value(string)
string.gsub(/.*?value.*?/, "\\1")
end
def matches_value_ignore_case(string)
string.downcase == "value"
end
#tests
[:matches_value, :contains_value, :matches_value_ignore_case].each_with_index do |method, index|
test = data[index]
value …Run Code Online (Sandbox Code Playgroud) 给定以下代码片段,100% 的决策覆盖率需要多少次测试?
if width > length then
biggest_dimension = width
if height > width then
biggest_dimension = height
end_if
else
biggest_dimension = length
if height > length then
biggest_dimension = height
end_if
end_if
Run Code Online (Sandbox Code Playgroud)
上述问题的答案是 4 。100% 决策覆盖需要 4 个测试用例。谁能说出以下问题的答案解释?
我正在做一些测试。我有一个文件dao.go:
package model_dao
import "io/ioutil"
const fileExtension = ".txt"
type Page struct {
Title string
Body []byte
}
func (p Page) SaveAsFile() (e error) {
p.Title = p.Title + fileExtension
return ioutil.WriteFile(p.Title, p.Body, 0600)
}
func LoadFromFile(title string) (*Page, error) {
fileName := title + fileExtension
body, err := ioutil.ReadFile(fileName)
if err != nil {
return nil, err
}
return &Page{title, body}, nil
}
Run Code Online (Sandbox Code Playgroud)
还有一个测试文件dao_test.go:
package model_dao_test
import (
"shopserver/model/dao"
"testing"
)
func TestDAOFileWorks(t *testing.T) {
TITLE := "test"
BODY …Run Code Online (Sandbox Code Playgroud) public class ConfigValues
{
public static final String url = "https://www.google.com/";
..//more properties
}
Run Code Online (Sandbox Code Playgroud)
为什么以上一个不被认为是好的,但创建单独的.properties文件被认为是好的做法?
我想知道是否仅将用于测试的库包含在最终的构建发行版中。我在go.mod/ go.sum文件中看到了依赖项,但无法检查最终的二进制文件。
我猜想Go构建工具可以某种方式处理冗余代码,但是我没有找到任何证据。
有人可以指出我在文档中的位置还是描述行为?
回购/通用/logger.go
package common
var once sync.Once
var Logger *logrus.Logger
func InitLogger() {
once.Do(func() {
Logger = logrus.New()
Logger.Out = filename // file opened and *file assigned here for logging
})
return Logger
}
Run Code Online (Sandbox Code Playgroud)
回购/setup_test.go
package main
func setUp() {
common.InitLogger()
fmt.Println(common.Logger) // prints some pointer related things which means logger is initialized
}
func TestMain(m *testing.M) {
fmt.Println("Starting Test...")
setUp()
code := m.Run()
common.APILog.Println("Finishing Main...")
os.Exit(code)
}
Run Code Online (Sandbox Code Playgroud)
回购/车辆/品牌/马鲁蒂/汽车/mycar_test.go
package car
func TestMyFunc(t *testing.T) {
**t.Log(common.Logger) // When i run go …Run Code Online (Sandbox Code Playgroud) 我尝试计算 Go 应用程序启动和接受请求所需的时间。我尝试使用以下方法来做到这一点:
func main() {
start:=time.Now()
repo.CreateConnection()
router := mux.NewRouter()
r := bookController.Controller(router)
fmt.Println("Starting server on the port 8080...")
log.Fatal(http.ListenAndServe(":8080", r))
fmt.Println(time.Since(start))
}
Run Code Online (Sandbox Code Playgroud)
但控制台只打印直到 Starting server on the port 8080...
GOROOT=/usr/local/go #gosetup
GOPATH=/Users/admin/go #gosetup
/usr/local/go/bin/go build -o /private/var/folders/t3/1fk2w7y55qs1dfxbxbvpsn9h0000gp/T/___go_build_payments_go_performance go-performance #gosetup
/private/var/folders/t3/1fk2w7y55qs1dfxbxbvpsn9h0000gp/T/___go_build_go_performance
Successfully connected!
Starting server on the port 8080...
Run Code Online (Sandbox Code Playgroud)
有没有办法显示正确的启动时间?我所说的启动时间是指该应用程序开始侦听端口 8080 所需的时间。
在我的 go 程序中,main 方法执行以下操作:
port := flag.Int("port", 8080, "Port number to start service on")
flag.Parse()
Run Code Online (Sandbox Code Playgroud)
我有一个虚拟测试,如下所示:
func TestName(t *testing.T) {
fmt.Println("Hello there")
}
Run Code Online (Sandbox Code Playgroud)
当我运行测试(从 goland 或命令行)时,出现以下错误:
/usr/local/go/bin/go tool test2json -t /private/var/folders/7v/p2t5phhn6cn9hqwjnn_p95_80000gn/T/___TestName_in_github_tools....test -test.v -test.paniconexit0 -test.run ^\QTestName\E$
flag provided but not defined: -test.v
Usage of /private/var/folders/7v/p2t5phhn6cn9hqwjnn_p95_80000gn/T/___TestName_in_github_tools.....test:
-port int
Port number to start service on (default 8080)
Run Code Online (Sandbox Code Playgroud)
当我删除主文件中的标志行时,测试正常执行 请知道如何解决此问题?
提前致谢
嘿,我正在用 cypress 测试 React 应用程序,并使用 json-server 来测试一个假 api。
当我运行一些测试时,它将更改我的 db.json 文件的数据库。
因此计划是在每次测试后将数据库恢复到原始状态。
这是我的代码:
describe('Testing fake db to be restored to original database after
updating it in other test', () => {
let originalDb: any = null
it('Fetch the db.json file and then updating it to the original copy',
() => {
// Save a copy of the original database
cy.request('GET', 'localhost:8000/db').then(response => {
originalDb = response;
console.log(originalDb);
})
// Restore the original database
cy.wrap(originalDb).then(db => {
cy.request({
method: 'PUT',
url: …Run Code Online (Sandbox Code Playgroud) 我想比较一个Android设备和一个Linux虚拟机的计算性能.(我的硕士论文的一部分)测试必须使用某种输入(例如图像,或只是数字),并且必须也有一些输出.
例如,jar文件可以制作一些图像的全景图.或者也许是密码破解者.
另一个要求是,必须以编程方式启动测试.所以必须有可能,通过java方法调用启动全景制作或密码破解.
是否有开源项目或jar文件来进行此测试?
更新:链接的答案不是我搜索的:@linski有想法,没有实现.如果任务可能是"现实生活"情景会更好.例如,获取全景图,或破解密码.
UPDATE2:"测试必须使用某种输入(例如图像,或只是数字),并且必须也有一些输出." +"如果任务可能是"现实生活"情景会更好"
testing ×10
go ×5
java ×2
performance ×2
android ×1
cypress ×1
dispatch ×1
flags ×1
go-modules ×1
go-testing ×1
goland ×1
json-server ×1
manual ×1
proc ×1
processing ×1
reactjs ×1
request ×1
ruby ×1
symbols ×1
unit-testing ×1