testability

Scala: How to test methods that call System.exit()?

微笑、不失礼 提交于 2019-12-19 05:58:15
问题 I have been developing a command-line tool which calls System.exit() ( don't want to use exceptions instead of ) on certain inputs. I am familiar with Java: How to test methods that call System.exit()? and its the most elegant approach. Unfortunately, it is not enough pure, due to I had to add the dependencies to system-rules, junit-interface Is there any common pattern for dealing with System.exit in specs2 which is more pure than my current approach which don't use specs2 ? import org.junit

Should static classes be avoided because it makes Dependency Injection Difficult?

家住魔仙堡 提交于 2019-12-03 12:56:43
Somebody tasked with creating a "Core" set of libraries created a set of static classes providing all sorts of utilities from logging, auditing and common database access methods. I personally think this stinks because we now have a Core set of libraries that are hard to test because I can't mock / stub these classes or do any injection into their constructors. I suppose I can use TypeMock to stub these out but I'd rather do it for free. What do you think? Edit If you don't think they're hard to test could you give an example of how you would test them. These static classes instantiate other

Scala: How to test methods that call System.exit()?

我的梦境 提交于 2019-12-01 03:48:50
I have been developing a command-line tool which calls System.exit() ( don't want to use exceptions instead of ) on certain inputs. I am familiar with Java: How to test methods that call System.exit()? and its the most elegant approach . Unfortunately, it is not enough pure, due to I had to add the dependencies to system-rules , junit-interface Is there any common pattern for dealing with System.exit in specs2 which is more pure than my current approach which don't use specs2 ? import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.ExpectedSystemExit; public

inheritance vs. composition for testability

只谈情不闲聊 提交于 2019-11-30 03:27:33
While designing my objects I find composition to be a better choice from the perspective of testability. The reason being, I can mock parts of the composition structure if I need to, while running unit tests. This is not possible if I have an inheritance hierarchy. I would like to know if others have also found this to be a reason to prefer composition. Also what other testability pitfalls did you get into because inheritance was used? I believe that the more you start to develop using design patterns, you'll find more and more often where composition is going to be favored over inheritance. I

Do Extension Methods Hide Dependencies?

谁说胖子不能爱 提交于 2019-11-29 05:43:57
All, Wanted to get a few thoughts on this. Lately I am becoming more and more of a subscriber of "purist" DI/IOC principles when designing/developing. Part of this (a big part) involves making sure there is little coupling between my classes, and that their dependencies are resolved via the constructor (there are certainly other ways of managing this, but you get the idea). My basic premise is that extension methods violate the principles of DI/IOC. I created the following extension method that I use to ensure that the strings inserted into database tables are truncated to the right size:

inheritance vs. composition for testability

谁说胖子不能爱 提交于 2019-11-28 22:23:23
问题 While designing my objects I find composition to be a better choice from the perspective of testability. The reason being, I can mock parts of the composition structure if I need to, while running unit tests. This is not possible if I have an inheritance hierarchy. I would like to know if others have also found this to be a reason to prefer composition. Also what other testability pitfalls did you get into because inheritance was used? 回答1: I believe that the more you start to develop using

Do Extension Methods Hide Dependencies?

删除回忆录丶 提交于 2019-11-27 23:19:18
问题 All, Wanted to get a few thoughts on this. Lately I am becoming more and more of a subscriber of "purist" DI/IOC principles when designing/developing. Part of this (a big part) involves making sure there is little coupling between my classes, and that their dependencies are resolved via the constructor (there are certainly other ways of managing this, but you get the idea). My basic premise is that extension methods violate the principles of DI/IOC. I created the following extension method

Java: How to test methods that call System.exit()?

瘦欲@ 提交于 2019-11-26 03:18:05
问题 I\'ve got a few methods that should call System.exit() on certain inputs. Unfortunately, testing these cases causes JUnit to terminate! Putting the method calls in a new Thread doesn\'t seem to help, since System.exit() terminates the JVM, not just the current thread. Are there any common patterns for dealing with this? For example, can I subsitute a stub for System.exit() ? [EDIT] The class in question is actually a command-line tool which I\'m attempting to test inside JUnit. Maybe JUnit is