2013-07-23 457 views
1

我有一个斯波克集成测试,看起来是这样的:Grails的斯波克集成测试redirectedUrl本地主机测试应用程序,并构建服务器测试应用程序之间的不同

class PriceTierControllerIntegrationSpec extends IntegrationSpec { 

    PriceTierController controller 

    def setup() { 
     controller = new PriceTierController() 
    } 

    def "applyDiscount() method will redirect user to success view"() { 
     when: 
     controller.applyDiscount() 

     then: 
     controller.response.redirectedUrl == '/priceTier/success' 
    } 

然后在控制器,逻辑很简单:

class PriceTierController { 

    def applyDiscount() { 
     redirect action: 'success' 
    } 

    def success() { 
    } 
} 

当我在本地机器上运行这个Spock测试时,测试通过。然而,在构建服务器,我收到以下错误:

controller.response.redirectedUrl == '/priceTier/success' 
|   |  |    | 
|   |  /test/success false 
|   |      8 differences (46% similarity) 
|   |      /(t---)e(st--)/success 
|   |      /(pric)e(Tier)/success 
|    org.codeh[email protected]dc42543 
[email protected] 

出于某种原因,在构建服务器时,斯波克测试认为,控制器名称是test而不是priceTier,测试将失败。这似乎只发生在Spock集成测试中,因为Spock单元测试和一些遗留的Grails mixin测试都通过正常。

有没有人知道可能会导致这个问题?

+1

,请复制粘贴你用你的本地计算机上运行测试和构建服务器的命令。你使用不同的environemnt设置? –

回答

0

我也刚刚经历过这个相同的问题,它似乎归结为测试框架从测试类的名称中提取控制器名称。

的约定是,测试类名为<controller name>ControllerSpec

在上述情况下,测试类应该被命名为PriceTierControllerSpec,以便测试框架将成功地解决了控制器PriceTeir

根据这些准则命名类似乎解决了这个问题。

而且参考可以在这里找到:https://jira.grails.org/browse/GRAILS-10962