Unit Test Your Aspects 130
An anonymous reader writes "The widespread adoption of programmer testing over the past five years has been driven by the demonstrable productivity and quality of the resulting code. Find out why and how to do it, as this article introduces you to the benefits of testing aspect-oriented code and presents a catalog of patterns for testing crosscutting behavior in AspectJ."
Unit Testing In The Schools... (Score:4, Insightful)
Re:Unit Testing In The Schools... (Score:3, Insightful)
My software engineering course was fairly language independent (though most students used C++ since that was the primary language taught at this particular institution). Testing, in general, is a language independent craft.
I guess what I'm saying is that I disagree with your premise of unit testing only being taught in Java courses. I would gues
Re:Unit Testing In The Schools... (Score:5, Interesting)
I've recently been working on a BlueJ extension for PMD [blogs.com] and he's quite active on the bluej-discuss list.
Re:Unit Testing In The Schools... (Score:2)
I been taking courses at the local community college for the last five years on a part-time basis. Java is the only language course where the instructors stress that the input/output of functions should be tested/validated when designing the program. The other instructors either don't care much for the language they are teaching to emphasize thi
Re:Unit Testing In The Schools... (Score:2)
I have also worked as a developer and system tester for over 15 years, primarily in C/C++, every single employer has demanded documented unit t
Re:Unit Testing In The Schools... (Score:1)
Re:Unit Testing In The Schools... (Score:5, Insightful)
Blame it on JUnit. Since it provides a way to make unit testing easier, it's easier to get people to actually do it. When I was in school, we talked about unit testing, but never really did it very well. By employing the latest buzzwords such as JUnit and Spring in your design, it's much less work to build your unit tests that it would be with other languages.
I also think, for better or worse, the the Java community is much more open to the latest toys than users of the other established languages are, which may explain why the XUnit variants in other languages haven't taken off as well.
Re:Unit Testing In The Schools... (Score:1)
DUnit does exactly the same for Delphi, we are using it at my workplace together with a somewhat more advanced automated testing framework built around it. Works very nicely I have to admit, setting up test cases and collections takes only a few minutes for a new class. Throw in a test-driven XP development model and the result is a very dynamic and flexible development cycle, yet with a very
Re:Unit Testing In The Schools... (Score:3, Insightful)
At this point I'd like to point out the existence of JML [iastate.edu], an annotation syntax and set of associated tools for Java that makes a lot of things easier
Re:Unit Testing In The Schools... (Score:2)
Don't forget NUnit [nunit.org], which allows JUnit-style unit tests to be constructed for
Re:Unit Testing In The Schools... (Score:2)
If it helps with your numbers, my company uses it (along with NMock [nmock.org] — whose site appears to be down, ironically because of a problem with Java — for isolation) for all .NET projects.
I love how they've used attributes in the implementation, makes things very easy. The Java (1.)5.0 implementation of JUnit uses this approach too, I believe.
Re:Unit Testing In The Schools... (Score:2)
Re:Unit Testing In The Schools... (Score:2, Informative)
Re:Unit Testing In The Schools... (Score:2)
Writing a test for an algorithm takes x4 the effort for the algorithm itself. Having garbage collection on board makes writing the test much easier than when not having garbage collection.
The mental effort required to write code with manual memory management is tremendous. Imagine this effort quadrupled for writing the test, and y
Re:Unit Testing In The Schools... (Score:2)
That's a really interesting point. My first reaction to the question was to say that Java lets you write code faster, not so much re-inventing the wheel; that the richness of available library functions allows the test writer that much more speed and flexibility. But I think you've actually hit on the real reason that test frameworks for C++ are so difficult, and so unreliable. Since most of the bad (that is non-obvious) C++ bugs tend to be memory rel
Re:Unit Testing In The Schools... (Score:2)
-matthew
Re:Unit Testing In The Schools... (Score:2)
Re:Unit Testing In The Schools... (Score:1)
Re:Unit Testing In The Schools... (Score:2, Informative)
in JAVA you test, in C/C++ you debug (Score:1)
Re:Unit Testing In The Schools... (Score:2)
The schools will catch up soon enough.
Re:Unit Testing In The Schools... (Score:2, Funny)
Simple reason:
C/C++ programmers: It works, dammit! We don't need no stinkin' testing.
C# programmers: The compiler would warn or fail if it didn't work; if anything goes wrong in production, we'll patch it in the next release.
Visual Basic programmers: Uh... testing? wuzzat?
-dZ.
Is this statement a joke? (Score:2)
The quality of software has been continually declining for the last decade, I think. If anything, we're just better at teaching users to avoid things that don't work.
Re:Is this statement a joke? (Score:2)
Software Engineering is making leaps and bounds, so there are many tools available for writing good software. The people who really know what they are doing have more at their disposal. However, more than ever, there are a very large number of incompetent developers out there. It's much easier to get into programming now than it was in the machine language/assembly/C days because things are much easier to use, and the too
Re:Is this statement a joke? (Score:3, Insightful)
"However, more than ever, there are a very large number of incompetent developers out there."
Do you think that these statements are related in any way? I mean, using software evaluation / developmentation method X seems to be the equivilant of having a safety net. And there's definately a lot of developers out there that need one.
Re:Is this statement a joke? (Score:3, Interesting)
Thank God for the 2000 tech crash! (Score:2)
Thank God for the 2000 tech crash! Any programmer who doesn't do some amount of their own testing is a moron. I think the lack of testing is a leftover from the time when English majors were getting dev jobs at dot-coms...
Re:Thank God for the 2000 tech crash! (Score:3, Funny)
Re:Is this statement a joke? (Score:2)
Gnome 0.1 (98 ish) was more stable then 2.12?
Web pages worked better in Netscape 1.2 then they do in Firefox 1.1?
The Standard File sytem back then was like Fat32. dude NTFS, ext3, RieserFS are all much better then what was avalible.
I think you really need to go back an look at the Apps you were using in 95 dude.
before, posting flame bait like this.
p.s. you sir are a WANKER!
hmph (Score:4, Funny)
Re:hmph (Score:1)
Re:hmph (Score:3, Funny)
I unit test all the programmers I hire... (Score:2, Funny)
I do inquire if they have any siblings that may be been properly engineered.
Programmer testing? (Score:2, Informative)
Programmer testing? That means testing programmers, as in certifying them? Apparently not.
From the article, it is clear that they are referring more to testing of programs. Of course, then one might wonder who would think that nobody ever tested any programs prior to 5 years ago.
Reading a bit mor
Re:Programmer testing? (Score:5, Interesting)
From the context, it seemed pretty obvious to me that "programmer testing" means testing that is performed by programmers, as opposed to by a separate part of the development team that specializes in testing.
Having the programmer do some of the testing of his/her own code makes sense to me for several reasons:
I'm sure there are other reasons, but the point is this: in many cases, increasing the amount of testing that the programmer can do is advantageous. (At least up to a point -- you need a second pair of eyes, and you need someone who tests how all the modules interact to see if the system as a whole works as expected.) But still, finding ways to make it possible and to make it easy for programmers to add more tests and better tests is usually a good thing.
Re:Programmer testing? (Score:2)
Agreed, but I find that a lot of the time, particularly when working on projects where the requirements can change, unit testing provides a kind of documentation in itself. Even if the programmer has been too lazy to update the documentation for a method, the test itself must have been updated, so the functionality — provided that the tests have sufficient coverage — is described in the expectations of
Re:Programmer testing? (Score:2)
Re:Programmer testing? (Score:1)
A clearly written and exhaustive SPECIFICATION is the best and only thing required for a successful program. Documentation, architecture, user manuals, and testing all derive directly from the SPECIFICATION.
Really, it works. Focus your effort on hammering out the speciification and you'll be amazed how easy the rest of the job is.
As for JUnit: I've never tried it, is it fattening?
Less time for proper testing (Score:5, Interesting)
Re:Less time for proper testing (Score:2)
Yeah, but what is proper testing? Nowadays, really good testing needs to be an ongoing part of the development process. Everything the client sees, even the fir
Re:Less time for proper testing (Score:2, Insightful)
Re:Makes me wonder (Score:2)
Does the typical programmer code s significant chunk of programming before testing, or are there short spurts of code, then test, then code...?
Re:Less time for proper testing (Score:2)
Since I don't have a life-time of experience working with insurance (only the
Re:Less time for proper testing (Score:2)
You know, no matter how many times I hit that stupid "Preview" button, I invariably miss something!
Re:Less time for proper testing (Score:3, Insightful)
And if you really want to get serious about tests, there is technique where you program the tests BEFORE you implement the code. You just keep running the tes
Re:Less time for proper testing (Score:3, Interesting)
- You are now familiar with the functionality of that piece of code, so writing a test should be easy.
- Having a test ensures that no future code changes will cause the same bug (it is very embarassing to re-introduce a fixed bug).
- Having a test also ensures that other code changes don't affect anything related to this functionality working. This can also help uncover unnecessar
Re:Less time for proper testing (Score:3, Informative)
Re:Less time for proper testing (Score:2)
Re:Less time for proper testing (Score:2)
Keep testing!
Re:Less time for proper testing (Score:3, Informative)
That may be a possible choice with traditional QA testing (which you do right at the end), but that's not the notion with unit testing. I don't write tests to increase quality as such; I write them to increase my development speed. If the code usually works, I spend very little time debugging. When I do make mistakes, the test coverage means I generally find out right away about bugs, so the problems are easy
Re:Less time for proper testing (Score:2)
When you add a find-fix cycle to either one (ie: prior to shipping to a customer), times can increase quite dramatically.
I would further state (in my experience) that find-fix cycles on code that does not have automated, repeatable tests (be they integration or unit)
Ironic (Score:5, Funny)
How to always get your post on developers.slashdot (Score:1, Funny)
2. Pick a recent article on your chosen site.
3. Paraphrase the article in a few sentences, or if thats too difficult, just cut and paste the first few sentences of the article.
4. Post your paraphrase/cut and paste, along with a link to the article, to slashdot.
5. Bask in the glory as people attribute your ability to find an article with actually knowing
For .Net Developers... (Score:4, Informative)
http://www.nunit.org/ [nunit.org]
Then, read Marc Clifton's series on Advanced Unit Testing in C#. The code is easily ported to VB.Net, as well, although not required. I am working on introducing the practices outlined in the article where I am currently employed.
http://www.codeproject.com/csharp/autp1.asp [codeproject.com]
http://www.codeproject.com/csharp/autp2.asp [codeproject.com]
http://www.codeproject.com/csharp/autp3.asp [codeproject.com]
http://www.codeproject.com/csharp/autp4.asp [codeproject.com]
As if CodeProject wasn't slow enough. The readthroughs on this post should bring it to its knees in no time at all. If you have a chance, look at some of Marc's other postings, as well. Very high quality stuff.
In regards to Unit Testing in general, I don't know why it isn't given more weight in college coursework. Honestly, it would make a great course, or series of courses. I've been out of school for just a wee bit though, so maybe some are offering it already. ;-)
Re:For .Net Developers... (Score:1)
This is slightly offtopic, but does anyone know of a site similar to codeproject.com that's less Windows specific or more Linux specific? Code Project has a lot of useful code and interesting articles, but even the OpenGL and Java Programming sections are mostly Windows specific, so they're less useful than they could be. So far the closest I've found is Artima.com.
Aspect-oriented? (Score:3, Interesting)
wtf is Aspect-oriented programming?
how does it relate to object-oriented programming?
Re:Aspect-oriented? (Score:5, Informative)
In software engineering, the programming paradigm of aspect-oriented programming (AOP), also called aspect-oriented software development (AOSD), attempts to aid programmers in the separation of concerns, or the breaking down of a program into distinct parts that overlap in functionality as little as possible. In particular, AOP focuses on the modularization and encapsulation of cross-cutting concerns.
Re:Aspect-oriented? (Score:5, Informative)
And it's just that kind of buzzword-to-noise ratio that makes people ignore AOP.
In reality, AOP is a structured way for a programmer to modify existing classes an an OO system without sub-classing. So, here's AOP in Perl, just as an example: I used Perl's stackless-invocation goto semantics here for two reasons: it's the most efficient way to do this; but it's also an eye-catcher that (because of the bad blood programmers tend to have with respect to C or BASIC style goto) highlights what I think the problem is.
I tend to try to avoid this kind of thing in my programs, regardless of language, except where I make it very clear that functionality can and should be added, in which case I provide a mechanism. So, I'm not sure how AOP could work well (it's supposed to be used in those cases where the original author didn't have any idea about what you want to do). Sub-classing or re-writing such code has always seemed the right way to go to me.
How, for example, are you supposed to maintain code where a substantial change to any library routine's internal behavior could cause catastrophy for someone who has tried to add behavior to it? I suppose you could lexically scope such constructs, which would be reasonable, but no... I think this is just an attempt to get a small portion of what smalltalk or ruby style mix-ins/traits would give you.
Then again, I guess the problem really stems from trying to use a high-level language (Java) which attempts to simulate the constraints of a low-level language (C or C++) while users attempt to use it as if it were high-level (like Smalltalk, Haskell, Python, Perl or Ruby).
In the end, it seems to make more sense to use Java the way it was intended to be used, and use high level languages where you want dynamic features like the ability to reach into someone else's code and do whatever you like.
Re:Aspect-oriented? (Score:3, Insightful)
Sorry, my mod points just ran out, or you'd have been (+1, Insightful).
Speaking of moderation, the fact that a post quoting the phrase "modularization and encapsulation of cross-cutting concerns" was modded (+1, Informative) is itself (+1, Funny). :-)
Maybe it's just me, but I've never appreciated what's supposed to be so great about aspects. Yes, it might be useful to be able to introduce some debugging diagnostics at the start and end of every function automatically. We use a pretty powerful instrument
Re:Aspect-oriented? (Score:2)
Assembler is a low level language.
The distinction is not firm, and in reality it's a relative assessment of the scope and abstraction of a language which varys with respect to time. In 2100, we might well consider Perl or Smalltalk to be "low level languages" because they have no constructs for directly representing the state of the programmer's brain. That's hyperbolic, of course, but you get the idea. "High level" is whatever "low level" isn't, and right now, that's languages li
Re:Aspect-oriented? (Score:5, Interesting)
The promise of this is that you can save some effort by reducing repetitive function calls. The risk is that control flow can be very difficult to trace. Some people argue that aspect-oriented programming is similar to programming with goto, and I'm inclined to agree with them. It's useful under certain tightly defined circumstances and harmful otherwise.
Re:Aspect-oriented? (Score:3, Funny)
Is that like intercals "COME FROM" construct.
Re:Aspect-oriented? (Score:2)
Re:Aspect-oriented? (Score:2, Insightful)
What you do is you write a piece of code where part of it is a regular expression that matches one or more methods in your existing code, and another part is either the symbol "before", "after", or "both".
When you compile the code, the aspect's code is inserted before, after, or both before and after, the existing code. Your source isn't changed, just the binary.
So if every time the method Foo() is called you want it to call Bar() before and
Re:Aspect-oriented? (Score:1)
Here's a better question for the AOP crowd: Can you *possibly* come up with a new example usagage? Since its introduction, AOP snake-oil types have been dragging out the now-threadbare "logging" example (see the other replies to the parent). Are there any more uses for this thing?
Re:Aspect-oriented? (Score:2)
Mixins are a good example of AOP doing something powerful. AOP is a particularly good way of augmenting the functionality of objects without actually having to make those objects aware of that functionality by explicitly inheriting an interface.
You can find a good example using a Lockable interface -- to make an y object temporarily immutable -- in the Spring reference documentation. [springframework.org]
Re:Aspect-oriented? (Score:1)
Re:Aspect-oriented? (Score:1)
Re:Aspect-oriented? (Score:4, Insightful)
Aspect Oriented Programming is actually just a remake of the old comefrom [wikipedia.org] pun. However, AOP is not a pun. It's a real life atrocity that should have been slain at birth. It can be visualized as having a piece of code "steal" the instruction pointer from somewhere inside another piece of code. And some morons seem to think that this constitutes good software engineering...
No, I'm not shitting you here, it's actually true! It just sounds like a joke.
And for the record: No, I don't hate Java. Quite on the contrary, I love Java. Furthermore, I am a heavily certified and devoted Java-only developer, and have been for 7 years. But AOP is a big-time fuck-up.
>> how does it relate to object-oriented programming?
It doesn't. Then again, most developers don't even know exactly what OOP really is, and what conceptually separates it from other paradigms. Hell, most "developers" don't even know what a programming language paradigm is.
So it all boils down to the buzzword factor.
Re:Aspect-oriented? (Score:5, Insightful)
Aspects are great because the provide a useful means to abstract the relationships for policies, so we can finally cleanly capture hard problems like performance monitoring, consistent error handling, enforcing data security, or allowing product line variability for changing features in an application. This last one is the strategic reason for IBM investing: they can open source components but still integrate with different runtimes.
Obviously you've considered this really carefully. I can just imagine your intellectual predecessors sitting there 25 years ago fuming about how polymorphism makes it impossible to tell where a call in the program goes. "Leave my line numbers ALONE"
Aspects are great because the fact is that traditional OO just doesn't do a good job of modularizing (look it up) these hard but important problems. Of course, you also should consider the real world consequences of this problem (code gen, overweening frameworks, fragile code, etc.) Aspects promote good maintainable software for the real world. Just as was the case with OO, this new level of indirection requires some learning and good tools support.
Re:Aspect-oriented? (Score:2, Insightful)
Re:Aspect-oriented? (Score:3, Informative)
And some morons seem to think that this constitutes good software engineering...
The "moron" in question here is Nicholas Lesiecki, author of Java Tools for Extreme Programming: Mastering Open Source Tools Including Ant, JUnit, and Cactus [amazon.com]. This review [ercb.com] in Dr. Dobb's Journal calls it "original and useful".
He is also a contributor to Cactus [apache.org], "a simple test framework for unit testing server-side java code", part of the Apache Jakarta project.
He is currently a software engineer and programming instructor wit
Re:Aspect-oriented? (Score:3, Informative)
Re:Aspect-oriented? (Score:2)
One of the major applications that convinced IBM into AOP was to implement a new logging technique into a big system. Obviously it would take thousands of man hours if you went and did it manually (even if it was outsourced to India!). With AOP IBM realized that they can define the cut-crossing concern, for example, at the end of all methods that communicated to an IO devic
Related Reference (Score:5, Informative)
Re:Related Reference (Score:2)
Unit Testing, Extreme Programming, Agile (Score:2)
Nice examples (Score:1)
Because Fortran programming works in some contexts (Score:2)
For what it's used for, the general environment is very well tailored for the task, and the code in question tends to be a mix of simple text parsing and fairly complex computations, so a language
Re:Because Fortran programming works in some conte (Score:1)
I just would not agree with you on the global variables and initialization. Complexity of data exchange via global variables beats every attempt to debug such code. Your initialization helps to avoid some mistakes, but the basic problem remains. Exchange of information through
Edsger Wybe Dijkstra's qoute (Score:3, Insightful)
Re:Edsger Wybe Dijkstra's qoute (Score:2, Interesting)
Re:Edsger Wybe Dijkstra's qoute (Score:2)
Re:Edsger Wybe Dijkstra's qoute (Score:1)
Re:Edsger Wybe Dijkstra's qoute (Score:1)
Another methodology bandwagon (Score:2, Insightful)
Bring back the concept of RAPID application development. The only thing that was missing over 10 years ago was scalability. Today's frameworks are bloated and horrible. Testing will be much simpler, and requ
Re:Another methodology bandwagon (Score:2)
Agile is not at all based on RAD. I crave the days that you could drag a dozen components onto a frame, write a few lines of code and have an actual well behaving prototype sitting on the screen. I have an honest question for you. Did you ever work with VB, Delphi or perhaps CBuilder?
Spring is awful. Inversion of control is a silly concept. Yes you write less code, but it's all externalised where it's hard to
Re:Another methodology bandwagon (Score:2)
JUnit, J2EE and all the frameworks that surround this technology are nothing more than tools. The tools can be good or bad, suited or unsuited to a task. Unskil
Not sure about the example... (Score:2)
I got nothing against Aspects, but I just think they should be used when they make sense, like everything else I guess.
Re:Not sure about the example... (Score:1)
i guess the author (i didn't read it of course) wanted to use something a bit more colorful than the typical logging example. there's many many places where aspects make sense, and most of those places have to do with extracting the layers of cruft we've added to our software layers. most of that cruft serves a usefull purpose, but gets in the way of application logic (security, logging, transactions, framework baggage).
Perl's xUnit vs Test::Harness (Score:1)
But perl has Test::Class [cpan.org] which does a whole xUnit type thing inside the Test::Harness framework. Nice. However it also tells me on that page, not to bother with it unless I'm reduplicating the same code over and over in my tests -- which I usually do not.
I guess Test::Harness is plenty for average joes like me.
"Programmer Testing" - Is That New ? (Score:1)
OMG - you mean .. when I tested all that code I wrote between 1973 and 2000 I was doing something *different* from all you guys ?!
Why didn't someone tell me I was doing it wrong ?
(Seriously, WTF does that sentence even mean ?)
There is a suprise in Aspect-J (Score:2, Interesting)
When you move beyond the trivial examples, you will encounter Aspect-J's long-standing bugs that simply crash your IDE every five minutes. For example, this P1 critical bug makes Aspect-J unbearable:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=4421 5 [eclipse.org]
I've heard of JBoss AOP being used successfully in production (http://www.jboss.org/products/aop [jboss.org]).
AOP vs Lisp tracing (Score:1)
Re:AOP vs Lisp tracing (Score:1)
So far I have been logging in lisp only using a homewritten trivial 'tracer' macro.
Unit testing versus other methods of debugging (Score:1)
Worked with AOP (Score:3, Insightful)
Software Patents Considered Harmful (Score:2, Insightful)
And since Aspect-Oriented programming is a patented technique http://www.pmg.lcs.mit.edu/~chandra/publications/a op.html [mit.edu] , basically you can not use it.
So, who really cares if its theoretically any good, when legally it is worthless?
See US patents 6,467,086 and 6,442,750 :
http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PT O1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/srchnum.htm &r=1&f=G&l=50&s1=6,467,086.WKU.&OS=PN/6,467,086&RS =PN/6,467,0 [uspto.gov]