Redian新闻
>
what is really hard is testing
avatar
what is really hard is testing# Java - 爪哇娇娃
c*n
1
recently went through a lot of spring code testing, using mocks and in-mem
h2 db.
spring is kind of a mess, u declare a @component, and then it becomes global
accessible to everyone. as u accumulate more and more library dependencies,
all those @component (or those beans declared in the contexts) become like
trash to you, it's almost like the global variables in C coding days
avatar
w*z
2
DI is useful , but sometimes it is a bit messy, hard to know what is going
on. I have seen big applicationcontext.XML with hundreds of lines, bit
painful going through it.

global
dependencies,
like

【在 c******n 的大作中提到】
: recently went through a lot of spring code testing, using mocks and in-mem
: h2 db.
: spring is kind of a mess, u declare a @component, and then it becomes global
: accessible to everyone. as u accumulate more and more library dependencies,
: all those @component (or those beans declared in the contexts) become like
: trash to you, it's almost like the global variables in C coding days

avatar
g*g
3
I don't quite understand your complaint. It wasn't like the alternative is
easier to test. @Component is like a global service that has namespace, that
's much different from global variables. With mockito you can inject mock
dependencies for unit test.

global
dependencies,
like

【在 c******n 的大作中提到】
: recently went through a lot of spring code testing, using mocks and in-mem
: h2 db.
: spring is kind of a mess, u declare a @component, and then it becomes global
: accessible to everyone. as u accumulate more and more library dependencies,
: all those @component (or those beans declared in the contexts) become like
: trash to you, it's almost like the global variables in C coding days

avatar
c*n
4
--- "@Component is like a global service that has namespace"
what is the namespace ?
if in 2 libraries, written by 2 people, both mark
@Component
public class AuthorA implements SomeInterface {
}
@Component
public class AuthorB implements SomeInterface {
}
now in my application code, I just want to grab an "author", and do
public class MyTestSuite {
@Autowired
SomeInterface blah;
...
}
here since AuthorA and AuthorB are both discovered as "@Component", they are
like global variables, and makes my test fail to resolve the auto-wire of
SomeInterface. well my complaint is not really about tests only, just that
I found these issues during tests. my point was more "it's difficult to
provide a set of tests that prove that your code works given this huge
global context containing everyone's trash beans "

that

【在 g*****g 的大作中提到】
: I don't quite understand your complaint. It wasn't like the alternative is
: easier to test. @Component is like a global service that has namespace, that
: 's much different from global variables. With mockito you can inject mock
: dependencies for unit test.
:
: global
: dependencies,
: like

avatar
g*g
5
The namespace is the classname, which is global unique.
An interface implemented by two classes, while commonly seen, is not gonna
be the majority of your beans. And you can always use @Qualifier

【在 c******n 的大作中提到】
: --- "@Component is like a global service that has namespace"
: what is the namespace ?
: if in 2 libraries, written by 2 people, both mark
: @Component
: public class AuthorA implements SomeInterface {
: }
: @Component
: public class AuthorB implements SomeInterface {
: }
: now in my application code, I just want to grab an "author", and do

avatar
c*n
6
that is not a proper namespace, it's exactly the same false argument that u
can make global vars work by giving them "unique" names

【在 g*****g 的大作中提到】
: The namespace is the classname, which is global unique.
: An interface implemented by two classes, while commonly seen, is not gonna
: be the majority of your beans. And you can always use @Qualifier

avatar
g*g
7
It's global service, not global variable. I don't think OOP is against
global service. And as I said, @Qualifier can solve your problem.

u

【在 c******n 的大作中提到】
: that is not a proper namespace, it's exactly the same false argument that u
: can make global vars work by giving them "unique" names

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。