将函数导入到不在同一目录中的测试的最佳方法是什么?
例子
src
Get-Emoji.ps1
test
Get-Emoji.Tests.ps1
Run Code Online (Sandbox Code Playgroud)
[2]导入测试的函数Pester 认为所有名为 .Tests.ps1 的文件都是测试文件。这是几乎所有项目都使用的默认命名约定。
测试文件放置在与其测试的代码相同的目录中。每个文件都作为它测试的函数被调用。这意味着对于 Get-Emoji 函数,我们会将 Get-Emoji.Tests.ps1 和 Get-Emoji.ps1 放在同一目录中。将测试引用到 Pester 中的函数的最佳方式是什么?
Pester 测试放置在 .Tests.ps1 文件中,例如 Get-Emoji.Tests.ps1。代码位于Get-Emoji.ps1中。
为了使测试代码可供测试,我们需要导入代码文件。这是通过将文件点源到当前范围来完成的,如下所示:
实施例1
Run Code Online (Sandbox Code Playgroud)# at the top of Get-Emoji.Tests.ps1 BeforeAll { . $PSScriptRoot/Get-Emoji.ps1 }实施例2
Run Code Online (Sandbox Code Playgroud)# at the top of Get-Emoji.Tests.ps1 BeforeAll { . $PSCommandPath.Replace('.Tests.ps1','.ps1') }
为项目配置和使用 url 的最佳方法是什么
...作为示例,我们有这样的情况
水果应用程序
色彩应用程序
...和这样的测试
test('Navigate to fruits/banana', async () => {
await page.goto('https://https://dev.fruits.com/banana/');
...
});
test('Navigate to colors/red', async () => {
await page.goto('https://https://dev.colors.com/red/');
...
});
Run Code Online (Sandbox Code Playgroud)
...我想去的地方