Let me summarize here my recent thoughts hoping we can open the
discussion about this new ideas.
Well testedby aims to get 2 main results:
1. Define test on interface and inject implementation in test
2. Run test only against modified classes
I think I have good discussions with you all about these two points, and
yo all perfectly understand what I have in mind with these 2 points
without deeper details.
I try to rethink these two points keeping in mind all comments and
concerns I got from you and community. I tryied t focus mainly on
concerns about coupling and cluttering of code.
For point 1 I still convinced annotations are the best way to take.
For point 2, even if I still convince annotation could get some great
plus in BDD or DbC approach, isn't the only way. I think we can go for a
sw that continue to launch tests starting from class under test, but we
have at least 2 way to get wich tests we have to run:
* Well, annotations as said
* Using coverage infos. Open source coverage tools don't take care
of single test coverage, but for example Clover (commercial
coverage tool from atlassian does) as well described here
http://blogs.atlassian.com/developer/2008/11/stop_testing_so_much.html
Point 2 is the "magic button" Randall would like to see in testedby
isn't it?
So I'm saying we have to extend (or write from scratch) a coverage tool,
open source taking care of single test coverage integrated with and used
by testedby to run our test.
So testedby will be able to use both annotation (and they would have
precedence) for who define them, or "magically" use coverage data to run
right tests. Annotation will remain for test injection for "Test the
interfaces" approach.
Moreover we would get the first open source coverage tool with a
per-test report. Of course we still need ant, eclipse and moreover
HUDSON plugin.
What about?
Shih-gian Lee wrote on 13/11/08 22:38:
> Hello,
>
> I am new to this group. I like the idea of testedby. I have read most
> of the comments on TSS and blog. I am still a little unclear about the
> concerns of coupling. If I understand the argument correctly, we
> already have logical coupling when doing JUnit testing. The logical
>
Yep, you are right about logical coupling. Concerns about a more
strictly coupling is because with testedby you would have to maintain
not only test classes but also clas under test when you refactoring a
test class. IMHO it' a pure theoretical concerns if you would have good
IDE tools. Anyway, my last post on this group aims to provide an
alternative for who don't like this coupling and cluttering (about
cluttering see my comment to your question)
> coupling comes from the test methods and test class. For best
> practices, the test methods and test class have the names of the
> actual class and methods we would like to test. I find this kind of
> logical coupling is insufficient. Many developers tend to forget to
> update the corresponding test method when updating a function. I find
> it very frustrating when there is a lack of "stronger" linkage between
> the test class and the class under test. So, I don't see it this kind
> of coupling is necessary a bad thing.
>
+1. And with BDD approach names convention could be absolutely bad.
> As for code cluttering, can you list some of the use cases for
> brainstorming?
>
Well very simple. If you have a lot of test stressing a single method
you would have a lot of annotation on the method under test. And it
drive t cluttering code. But it give also some advantage giving better
understandig of the code at a first look defining in fact contract for
methods, and exposing it in javadoc too.
John have also some ideas about how to get annotations more compacts and
easy to use? John, would you explain them to all?
But my last post aims to don't imposing use of annotations. You could
continue to use testedby defining contract with annotation on interfaces
(where is much more important) and still use testedby test executor
limiting test run only to ones stressing modified code. Being too much
impositive could drive community away from testedby, and I'm convinced
who will try testedby could get its plus and step by step will start to
use its features.
BTW removing the requirement of annotation make possible to start using
testedby on existing projects without modify existing code. And it's a
great plus to introduce testedby as common used tool. Isn't it?
> I have a day job as well and I will try to contribute to this
> discussion as much as possible. I really like the idea proposed by
> testedby and would like to see something good comes out of it.
>
And I hope you could lend an hand with the code too at some stage ;)
Thanks for the interest.
bye
S.
bye
S.
bye
S.
Shih-gian Lee wrote on 17/11/08 22:02:
> I agree. If we only annotate the interfaces, everything will run onI mean run only test that point to modified class under test. For
> testedby by convention. I am not so sure what do we mean by using test
> executor to stress modified code. Maybe I have not looked at the code,
> yet. I will try to download the code and take a look at it.
>
>
example if you have class A, B,C and test classes tesA, testB, testC and
you modify class A and B but not C testedby will run only testA and testB.
Randall Hauch wrote on 18/11/08 02:20:
>
> and then run it. This would be similar to "autotest" in the
> Ruby/Rails world.
Yep, that is what "inspired" me
>
> It sounds like this may be fundamentally different than a framework
> designed around specifying behaviors for interfaces and APIs. They
> both perhaps need the same information (what is the relationship
> between my code and my tests), but then use that information for
> different ends. Or maybe I'm seeing something that isn't there.
Yep you are right they need same informations, so why don't provide both
features?
More general it's the focus changing from test class to class/interface
under tests. Goals are different, but focus is the same. Moreover
developer may force "autotest" link between test classes and classes
under test with annotation (automatic discovering may be disabled)
providing an explicit link which have other problems (cluttering
mainly), but that could have sense in some case. What I'm saying is: we
should leave to developer choice if and when use auto discovery and when
explicit define annotation.
Both features could be provided by testedby since they aren't logically
related, but as you said use same meta data. Am I totally bad?
bye
S.
...Borrowing the example from your
original post (http://www.javalinux.it/wordpress/?p=116):
public interface APIInterface {
public int add(int a, int b);
}
@ContractFor( interface = "APIInterface")
public class APIContract {
private APIInterface instance;
public APIContract(APIInterface instance) {
this.instance = instance;
}
...
1. If there is annotations in classes under test (or interfaces
implemented by them) go for it
2. If there is annotations on test classes go for it
3. MAgic discovery based on metadata of eclipse (or collected by
coverage like tool)
>
> or the tooling could simply auto-generate and run contract tests for
> simple scenarios.
>
yep it would be useful for both approaches.
> Regarding the second item, is there any reason why generic tooling
> couldn't be adapted to each tooling environment (e.g., Eclipse, Ant,
> etc.) via its available plug-in/extension mechanisms that manages all
> the metadata related to a workspace such that it would be entirely
> responsible for maintaining the relationships between classes/methods
> and their associated tests? In other words, why can't the tooling
> alone allow me to right-click on a class/method and run all associated
> tests that reference that class/method - without any annotations other
> than those already provided by JUnit/TestNG/whatever?
>
We are in the same page here. Tool could do all itself.
IMHO we should let user specify annotations if they want for
"documentation" and to change the "standard" behaviour of the tool. For
example tool could get more tests than specified explicitly by user, but
user could exactly want to consider only test he have linked. In this
case tool should give a warning to user, but just run tests specified.
IOW I like your ideas because it's doable together mine, and I'm
convinced here that flexibility could give a serious spin to our TestedBy.
Please let me know if I'm totally wrong. Comment from all are very welcome.
Randall Hauch wrote on 18/11/08 22:02:
> On Tue, Nov 18, 2008 at 2:40 PM, Stefano Maestri
> <stefano...@javalinux.it <mailto:stefano...@javalinux.it>>
Not sure I'm following you. I'm referring to testedby annotation which
are defining contract/behaviour using unit test.
As said I'd like too to support great portion of tested by (the auto
test part IMHO) without any effort.
Just use annotation for 2 reasons:
1. Define contract
2. change default magic discover forcing your own link between test
class under tes.
>
> However, remember that with each annotation definition you can specify
> how the information is retained (in the source only, in the classes,
> or at runtime). So if any tested-by annotations are needed, those
> annotations could be made to be retained in source (or class file if
> needed).
Not sure to follow you also here. What do you mean exatly? For sure this
kind of annotation may stay in class or source (even if using pure
string as parameter the aren't a problem in runtime too).
bye
S.
Randall Hauch wrote on 18/11/08 22:02:
Not sure I'm following you. I'm referring to testedby annotation which> I agree with Stefano. If the annotations specify the behavior
> contract, then it is very valuable (i) for implementers, and (ii) for
> users of the API.
>
> Perhaps John was referring to the "tested by" annotations, which are
> important only for that project. I'd love to see the "tested-by"
> functionality (at least a good portion of it) work without any effort
> by the developer - and that includes not maintaining "tested-by"
> annotations.
are defining contract/behaviour using unit test.
As said I'd like too to support great portion of tested by (the auto
test part IMHO) without any effort.
Just use annotation for 2 reasons:
1. Define contract
2. change default magic discover forcing your own link between test
class under tes.
> However, remember that with each annotation definition you can specifyNot sure to follow you also here. What do you mean exatly? For sure this
> how the information is retained (in the source only, in the classes,
> or at runtime). So if any tested-by annotations are needed, those
> annotations could be made to be retained in source (or class file if
> needed).
kind of annotation may stay in class or source (even if using pure
string as parameter the aren't a problem in runtime too).
bye
S.
JPAV wrote on 19/11/08 17:09:
> On Nov 18, 3:02 pm, "Randall Hauch" <rha...@gmail.com> wrote:
>
>> I agree with Stefano. If the annotations specify the behavior contract,
>> then it is very valuable (i) for implementers, and (ii) for users of the
>> API.
>>
> I'm not disagreeing with this either. Going back to the idea that
> there are 2 issues we're discussing, a new annotation seems
> appropriate when talking about a contract. The only difference I'm
> proposing is to move the annotation to the contract code (i.e., the
> test code) rather than specifying it in the interface.
>
But, I think Randall was agreeing with me on put annotation on interface
to give implementers and users evidence of contract.
> Same net
> effect, but environments that need source but for whatever reason
> don't have access to test source wouldn't be confounded by not being
> able to process annotations that refer to missing entities. Not
> really sure how much of a real issue this is, but assuming it is, that
> would be the advantage of moving the annotation. Otherwise, having
> the annotation on the interface would be perfectly fine.
>
Well, not sure to follow you here: IMHO it's the contrary. If you put
annotation on interface and that annotation use pure strings as
parameters you don't need at all test code to compile. You see the
contract defined (at least the name of contracts) and then you can
compile and use it. When you want to verify contracts you need test
code, but at least you are advised there is a contract during your
implementation or even reading javadocs (which contain our annotation
since they are defined as @Documented). The contract verifacation is
matter of test, let me call it a TCK.
With you approach you haven't any advice of contract and you need test
code to get it.
let me remark that using pure string as parameter of annotation give us
the opportunity to compile and use interface even without test code.
Annotation will be used only by testedby test runner. It's exactly the
reason for which I've used string instead of class reference, to avoid a
real coupling. I think a lot of people have misunderstood me on this point.
Annotation as defined in my original post (with string parameter) don't
introduce compile time coupling between test class and class under test
> I'd also add that, IMO, something like @ContractFor(interface = XXX)
> (or, if specified on the interface, maybe @Contract(class = XXX))
> reads a bit better than @TestedBy and highlights that this is really
> about contracts and not just any type of testing.
>
Absolutely agree here. I said a lot of time that annotations name need
to be reviewed. @TestedBy have been good just in my first post to keep
it easy to read and understand without a lot of names and changes.
>> Perhaps John was referring to the "tested by" annotations, which are
>> important only for that project. I'd love to see the "tested-by"
>> functionality (at least a good portion of it) work without any effort by the
>> developer - and that includes not maintaining "tested-by" annotations.
>>
> Yes, this is part of what I was getting at.
>
And I almost agree here, as said in last posts. I'd just remark to leave
users the choice, with configurable priorities as said in my last post.
>> However, remember that with each annotation definition you can specify how
>> the information is retained (in the source only, in the classes, or at
>> runtime). So if any tested-by annotations are needed, those annotations
>> could be made to be retained in source (or class file if needed).
>>
>
> I wasn't addressing this aspect of annotations, but it's an
> interesting concern. I was more concerned about not having to
> specify, or more importantly maintain, annotations unless absolutely
> necessary, which seems only to establish a relationship between an
> interface and its contract such that all implementations are forced to
> adhere to both contract and interface. Not sure if I understand any
> need to "retain" the annotations anywhere other than source
May I insist that is better to have to maintain annotation defining
contracts in production code. IMHO they have too much value (if users
decide to use it, and we wouldn't force anyone) to don't maintain them.
Retain annotation at runtime may be needed to put them on javadoc, but
perhaps my memory could fail here..I've to check. For sure it make test
executor able to run against .class without code, but maybe it's not
strictly needed (even if is how JUnit and TestNG works actually)
bye
S.
2: We are currently also developing some serverside software. The software is meant to be run in a memory restricted environment.
We don't want to ship the behaviour classes because we are not doing runtime evaluation of the contracts and because we need to
save ram (sorry for that monster of a sentence). We also don't need to ship the contracts as there are only our own developers
working on this one.
In my eyes the best approach would be to support both scenarios:
strong coupling and no coupling
Cheers
Jochen
--
Jochen Mader
Development Lead
Dipl. Inf. (FH)
+49 941 604889701
Pramari
Bruderwöhrdstr. 15b
93055 Regensburg
bye
S.
Cheers
jochen