What are tangible advantages to proper Unit Tests over Functional Test called unit tests

A project I am working on has a bunch of legacy tests that were not properly mocked out. Because of this the only dependency it has is EasyMock, which doesn’t support statics, constructors with arguments, etc. The tests instead rely on database connections and such to “run” the tests. Adding powermock to handle these cases is being shot down as cost prohibitive due to the need to upgrade the existing project to support it (Another discussion).

My questions are, what are the REAL world tangible benifits of proper unit testing I can use to push back? Are there any? Am I just being a stickler by saying that bad unit tests (even if they work) are bad? Is code coverage just as effective?

3

  • Resources

    You need a test database to run the tests. The hardware to run the database is more expensive than using powermock. Releasing the resources used for unit testing against the database means the company doesn’t need to upgrade the server as soon.

  • Reliability

    A test can fail because the database is down or in an inconsistent state. Guess what, your builds failed because the DBAs took the dev server down during the day to do some upgrades (and now the developers are trying to figure out what went wrong in the code – when its not the code).

  • Additional maintenance

    Tests can be run in any order. Adding or removing a test should not cause the test suite to fail. Running against a database means there is some state somewhere (in the database). Typically, these tests require extra maintenance to ensure that the database maintains the proper state for the next test to run.

  • Concurrency

    Two developers run the unit tests at the same time. Having a database means that the tests may collide on the database. The solution to this would be to clone the database for each test that is run, which is prohibitive on a real database. Which leads to another option to consider.

Consider also using HSQLDB with whatever dialect of database you are using. This way one can create an in memory database for each test. A unit test runs, constructs the necessary database, loads the data, the database connection from the code connects to HSQLDB and runs against the test data.

My questions are, what are the REAL world tangible benifits of proper unit testing I can use to push back?

Good unit tests are (per Clean Code, and elsewhere):

  • Fast
  • Independent
  • Repeatable
  • Self-Validating
  • Timely

Not having true unit tests violates the first three (and usually the last one). This leads to some pretty significant problems:

  1. Your tests are slow. Slow tests get run infrequently. Tests that aren’t run are almost useless.
  2. Your tests can fail due to reasons unrelated to the code you’re testing. This makes it far harder to find out why tests have failed, wasting time and leading people to blame the environment rather than the code.
  3. As the database changes, your results change. Getting some database in a known good consistent, maintained state for tests is tedious, annoying and error-prone.

In general, a lack of isolation in unit tests leads to worse tests which take longer to write, longer to investiage, and provide less confidence in your codebase. That in turn leads to people writing less tests or ignoring the tests more which is the downward spiral to chaos.

Unit tests are just a tool used to help a developer deliver reliable code. If you think like your boss thinks, you will be able to convince him if what you are proposing makes sense. However, if you present it as an evangelist on a band wagon, you won’t get the resources allocated. You will need to explain to him how he benefits by spending the time and resources retrofitting unit tests to you legacy application.

You mentioned legacy tests – that implies legacy code. Unfortunately, fitting unit tests to code that was not designed to be unit tested is a difficult, time consuming and expensive process. The business case get even harder if you have tests that provide useful results, and all you are going to achieve is (from the business case POV) alternate tests providing the same results. You will need to focus on the cost(time) savings…..

My guess is that you will not be able to present your boss with a robust business case because there is not one.

1

From what you described it sounds like you don’t like test framework A and want to switch to test framework B, both of which work. Suck it up and use what is existing and working, don’t create more work reinventing the wheel so you can use your preferred test framework.

It takes more than a want to use the latest flavor of the month framework to justify throwing out existing working code and spending huge amounts of time and money for essentially zero benefit to users.

1

Good unit tests provide localization. Functional tests might tell you “the add user function is broken”, but a good unit test will tell you that it’s broken because somebody changed the USER.LAST_NAME field in the database to be non-null. It’s also possible to test small changes directly, instead of needing a complex test environment (which may need to be re-initialized or purged for some tests).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật