吸气剂的junit测试方法二传手 [英] junit test method for getters & setters

查看:70
本文介绍了吸气剂的junit测试方法二传手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有很多Java Bean.我需要为他们生成一个JUnit Test类.使用Eclipse 3.2及更高版本生成的测试方法; junit 4.4如下所示:

public void testGetName() {
        // fail("Not yet implemented");
    }

    @Test
    public void testSetName() {
        // fail("Not yet implemented");
    }

    @Test
    public void testGetEmployeeid() {
        // fail("Not yet implemented");
    }

    @Test
    public void testSetEmployeeid() {
        // fail("Not yet implemented");
    }

我的一些豆有100多个田野...

有没有一种方法可以使吸气剂和测试剂都得到单一的测试方法?设置程序,例如testEmployeeid()testName(),以便在这些方法中,我可以同时测试我的设置程序和&吸气剂,而不是使用2差异.他们的测试方法...

我应该如何配置eclipse来做到这一点?

解决方案

测试驱动开发"的理念是测试可能破坏的所有内容".也就是说,将精力集中在有用的测试上,而不是仅仅为了测试而编写测试.

字母和setter几乎总是琐碎的代码,不值得自己进行测试.

我知道这不是您认罪的直接答案,但我认为这可能仍然有助于指出这一点;-)那么,为什么您实际上首先需要为所有这些获取器和设置器编写测试? /p>

I have many java beans in my project. I need to generate a JUnit Test class for them. The test methods generated using Eclipse 3.2 & junit 4.4 look like the following:

public void testGetName() {
        // fail("Not yet implemented");
    }

    @Test
    public void testSetName() {
        // fail("Not yet implemented");
    }

    @Test
    public void testGetEmployeeid() {
        // fail("Not yet implemented");
    }

    @Test
    public void testSetEmployeeid() {
        // fail("Not yet implemented");
    }

some of my beans have more than 100 fields...

Is there a way by which I can get a single test method for both the getters & setters like testEmployeeid(), testName() so that in these methods I can test both my setters & getters rather than using 2 diff. test methods for them...

How should I configure eclipse to do this?

解决方案

The philosophy of Test Driven Development says "test everything which can possibly break". That is, focus your efforts on the useful tests, instead of writing tests for just the sake of it.

Getters and setters are almost always trivial code, which is not worth testing by themselves.

I know this is not a straight answer to your plea, but I thought it may still help to point this out ;-) So why do you actually need to write tests for all those getters and setters in the first place?

这篇关于吸气剂的junit测试方法二传手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆