Eri*_*son 35 grails unit-testing
我一直在通过输入运行我的Grails单元测试grails test-app :unit,它运行所有单元测试.有没有办法指定单个测试?
编辑: 到目前为止,每个人基本上都说同样的事情,但是当我这样做时,没有测试运行.还有什么想法?
结论: 好的,我使用的是测试类的名称,而不是被测试类的名称.一旦我尝试Foo而不是FooTests它完美地工作.
Rob*_*ska 42
您的设置可能出错的可能性:
您的命令顺序不正确.对我有用的是:
grails test-app -unit Foo(我的测试类在哪里FooTests.groovy)
您没有明确导入grails.test.GrailsUnitTestCase.
当我没有导入它时,我在识别我的测试时遇到了一些问题.当我扩展时GroovyTestCase,事情似乎正常.
这是一组适合我的测试示例.也许你可以发现它们和你的测试之间的一些差异?
注意:这些都是在testing安装插件的情况下运行的
测试/单元/ FooTests.groovy
import grails.test.GrailsUnitTestCase
class FooTest extends GrailsUnitTestCase {
void testFoo() {
assert true
}
void testBar() {
assert true
}
}
Run Code Online (Sandbox Code Playgroud)
测试/单元/ BarTests.groovy
import grails.test.GrailsUnitTestCase
class BarTest extends GrailsUnitTestCase {
void testFoo() {
assert true
}
void testBar() {
assert true
}
}
Run Code Online (Sandbox Code Playgroud)
测试/单位/我的/包装/ BazTests.groovy
package my.pkg
import grails.test.GrailsUnitTestCase
class BazTest extends GrailsUnitTestCase {
void testFoo() {
assert true
}
void testBar() {
assert true
}
}
Run Code Online (Sandbox Code Playgroud)
命令:所有单元测试
$ grails test-app -unit
...
Starting unit test phase ...
-------------------------------------------------------
Running 6 unit tests...
Running test my.pkg.BazTest...PASSED
Running test FooTest...PASSED
Running test BarTest...PASSED
Tests Completed in 847ms ...
-------------------------------------------------------
Tests passed: 6
Tests failed: 0
-------------------------------------------------------
...
Tests PASSED - view reports in target/test-reports
Run Code Online (Sandbox Code Playgroud)
命令:Foo单元测试
$ grails test-app -unit Foo
...
Starting unit test phase ...
-------------------------------------------------------
Running 1 unit test...
Running test FooTest...PASSED
Tests Completed in 815ms ...
-------------------------------------------------------
Tests passed: 2
Tests failed: 0
-------------------------------------------------------
...
Tests PASSED - view reports in target/test-reports
Run Code Online (Sandbox Code Playgroud)
命令:my.pkg.Baz单元测试
$ grails test-app -unit my.pkg.Baz
...
Starting unit test phase ...
-------------------------------------------------------
Running 2 unit tests...
Running test my.pkg.BazTest...PASSED
Tests Completed in 842ms ...
-------------------------------------------------------
Tests passed: 2
Tests failed: 0
-------------------------------------------------------
...
Tests PASSED - view reports in target/test-reports
Run Code Online (Sandbox Code Playgroud)
我在Grails 1.2.3和Grails 1.3.4中尝试过这些,两者表现相同.
hvg*_*des 12
就在这里
grails test-app -unit YourController.testSomething
Run Code Online (Sandbox Code Playgroud)
其中YourController是您的控制器,testSomething是测试方法.
你应该看到类似的东西
测试通过 - 查看报告
给定一个测试类foo.BarTests,您可以使用以下命令仅运行该类中的测试:
grails test-app :unit foo.Bar
Run Code Online (Sandbox Code Playgroud)
或者使用以下方法在该类中运行单个测试方法:
grails test-app :unit foo.Bar.testMethod
Run Code Online (Sandbox Code Playgroud)
请注意,在指定测试类的名称时,不要包含"测试"一词.
| 归档时间: |
|
| 查看次数: |
20084 次 |
| 最近记录: |