views:

113

answers:

4

If someone has created a small diagnostic, internal web app that uses (unit) tests as its logic, is there ever a valid reason to do that? Keep in mind that Nunit has to be deployed as well where ever this website goes.

I'm of the view that programs should contain their own logic and possibly reusable parts (if available) but not wrap tests for their logic. Tests serve the purpose of validation for code logic. If you than say tests are going to be code logic, shouldn't you need to write tests to validate the tests? Why is that fundamentally wrong?

Hint: Because now you are stringing all of these tests together and interrelating them, which means they are no longer dependent(?).

A: 

Code is code. Just because it's labeled a test doesn't mean it's not also a useful application.

Suppose we need to write a lot of verifications of beahviour. Why is using test framework a bad idea? SHoudl we instead write a new framework with identical function and call it something different?

Take an external view. This applciation claims to do certain things. Does it do them correctly? reliably? Can it be maintained, enhanced? Understood?

If so, why do you care that it happens to use a test framework in its implementation. If its behaviour or structure are defective then we criticise.

One lovely thing about great technology is that it has unexpected applications.

djna
A: 

I'm pretty sure if you look at this question TDD Anti-patters catalogue, you will find that you are commiting sever anti-patterns.

Gren
Which ones? I don't see any evidence of that (yet).
djna
I'd like to know as well.
4thSpace
The easy pick is you are using a unit test to run the happy path instead of testing. Another would be the Giant given the title of the question. And I can't tell if this is a single test or many tests but if one is using tests as actual logic your are probably using either the piggyback or the chain gang. By your comments I take it that I may have stretched it a little but it wasn't intentional. To me the idea of using tests as production code has a bad smell.
Gren
The patterns are, so far as I can see, all about how to organise tests and ensure tehir conmpleteness. There is no evidence here that these particular tests suffer from that. I'll agree that something doesn't "smell" right, but I was hoping to pull out the specifics of **why**. The arguments so far have not in anyway convinced me that the case in point has done anything wrong.
djna
+3  A: 

Using a Unit test framework for something else than unit tests is usually not the most proper path. You don't have to write tests for your unit tests, since you write them first and see them fail. That's how you know they're working properly. I'm guessing testing code written within a unit test framework is nontrivial, and if I had a diagnostics app for a critical piece of software, I would really like to be certain it worked as it should.

Edit: It seems that you've already made up your mind but need support in expressing why the current strategy is less than ideal to, perhaps, other project members. If that's the case, I suggest you put your code where your mouth is, and throw together a small sample app designed differently. If utilizing a unit test framework in this specific case was a bad design decision, then that would make it clear as sunshine.

Buhb
Who said that the tests are not themselves tested?
djna
I got the impression that the tests aren't tested from "If you than say tests are going to be code logic, shouldn't you need to write tests to validate the tests?"
Buhb
Manuel wolker of eclipse source had a blog post about tests and how to test tests not too long ago. His view is that the code tests the tests and the tests test the code. http://eclipsesource.com/blogs/2009/02/17/unit-testing-revelations/
Jean
I agree to some extent (see my answer above). But if you have a diagnostics app that, for instance, checks that a webapp is up by visiting a url, then just running the diagnostics app won't mean it's tested, since there are actually two possible expected outcomes, only one being tested.
Buhb
My point of view is that we have a diagnostic app. It's an app. We can test it just like any other. The fact that internally it might itself comprise tests is not relevent to how much testing of the app itself we choose to do.
djna
Ok, that is where I fundamentally disagree with you. Tests != re-useable business logic in production applications. By the posts, I can see this is an eye of the beholder scenario. The topic is very subjective so my question wasn't really that good
4thSpace
To some extent I'm playing Devil's Advocate. I think the question is really interesting and I'm glad you asked it. I wanted to get at the heart of the difference between a Test and Business Logic. You see, I think if you or I went off and implemented that diagnistic app some other way, we might well end up building something which **exactly** looks like the existing app - just it doesn't use the word test. I think there's an essential difference lurking, but we haven't yet verbalised it.
djna
A: 

The purpose of unit testing is to make sure your class works the way it should and according to the interface. So if you are using your unit tests for some testing app it seems like using assert in programm logic.

If you need some testing app - implement it and use WITH unit tests. It maybe to configure something or to get some user interaction.

One of the other reasons I see - unit test are written according to assumptions on how everything works. If your assumption is right tests should pass. When adding functionality unit tests let you feel confident that all assumptions are still there. So every test should be kept as simple as you can keep it. that`s why no need to test test code and no need to use testing code in any testing applications.

Yaroslav Yakovlev