Ouyangan
V2EX  ›  Java

针对 ssm 项目大家是怎样写单元测试的?

  •  
  •   Ouyangan · Jun 16, 2016 · 5600 views
    This topic created in 3641 days ago, the information mentioned may be changed or developed.

    我的疑惑三层都要写? 还是只需要写 controller 层?

    5 replies    2016-06-16 16:44:25 +08:00
    teemoer
        1
    teemoer  
       Jun 16, 2016
    junit 然后 class 类上面 @ContextConfiguration(locations = { "/applicationContext.xml" })

    extends AbstractTransactionalJUnit4SpringContextTests

    然后在类里面 autowird 属性 即可 使用.
    teemoer
        2
    teemoer  
       Jun 16, 2016
    补充下 controller 里面的 代码直接丢到 test 标注的方法 下面

    controller 用到的 service 层 使用 aotowird 即可 !

    不用谢
    Ouyangan
        3
    Ouyangan  
    OP
       Jun 16, 2016
    @teemoer 0.0 ,谢谢 , 我知道可以这样模拟 web 环境进行测试.... , 我的疑惑在于针对 service ,mapper,controller 三层都需要写单元测试不.
    Ouyangan
        4
    Ouyangan  
    OP
       Jun 16, 2016
    有没有老司机给个大公司 java 单元测试规范
    auin
        5
    auin  
       Jun 16, 2016
    按照经验来讲, SSM 基本都是做 web 项目,而 web 项目的测试重点必然是 web 页面,所以跑一边 service 层即可,其他两层没有单独列出来的必要
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2743 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 15:02 · PVG 23:02 · LAX 08:02 · JFK 11:02
    ♥ Do have faith in what you're doing.