views:

324

answers:

2

Hello,

We noticed that when testNG test cases extend TestCase (JUnit) those tests start executing as Junit tests. Also, I should probably mention, the tests are run through Maven.

Is this a bug or a feature? Is it possible to override this behavior and still run those types of tests as TestNG tests? Do you know a link where TestNG talks about this?

thanks.

+1  A: 

I didn't think either TestNG or JUnit required any base classes now that both use annotations to specify test methods. Why do you think you need to extend a class? And why on earth would a TestNG class extend the JUnit base class TestCase? Is it any surprise that they run as JUnit tests?

It sounds like neither bug nor feature but user error on your part. I'm not sure what you're getting at here. Why would you do this?

UPDATE: Your question is confusing me. Did you have JUnit tests running successfully that you're not trying to convert to TestNG, or visa versa? I'm having a very hard time understanding what you're trying to achieve here. Leave Maven out of it. It's immaterial whether they're run by you, Ant, or Maven.

duffymo
I am not saying one should extend Junit's BaseCase. If writing a TestNG test from scratch then yes the proper way to do it is to annotate your test classes with the @Test annotation and that's it. However, you don't have that ability when you are trying to migrate from Junit to TestNG. You cannot just blindly remove the extends clause in this case and throw @Test annotation everywhere
Uh, yes you can if you're using JUnit 4. And you should be.
duffymo
ok, one last try. in my project i have junit tests that i am running with Tesng. Those are legacy tests and since they are junit tests they extend a class. So, now when you annotate that test with the @Test annotation and run it with TestNG it gets run as a Junit test, but i want it to run with the characteristics of TestNG like setUp/teardown to be called once per test class, test methods don't need to start with the word test etc. But it looks like it's a default behavior of testng of the test extends BaseCase it's a junit test and that cannot be overridden
A: 

Looking at the maven surefire plugin info I can't see any way to select a test for TestNG processing only if it also extends a jUnit 3 class.

IFAIK your best bet is to just work on each class seperately, removing the jUnit references and then retesting. That way you never have the mixture in one class and you should avoid problems. To make the work manageable I would be inclined to do this only when I was changing a test case for some other reason.

Michael Rutherfurd
thanks Michael. I totally agree