spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.47k stars 38.09k forks source link

TestNG support in Spring Mocks [SPR-1555] #6253

Closed spring-projects-issues closed 12 years ago

spring-projects-issues commented 18 years ago

nebhale opened SPR-1555 and commented

I'd like to see support for the TestNG framework in the Spring Mocks area. To that end, I've gone ahead and done an initial conversion using the existing AbstractSpringContextTest and it's subclasses. As I worked on it, I felt that there was a ton of logic that would have to be duplicated in both trees and can probably be abstracted in some way. In addition there's backwards compatibility using XBean for TestNG if you want to support pre 1.5 (non-annotation) use of TestNG.

As far as the changes go, I simply removed the TestCase extension point and used annotations to get the setUp() method to run at the beginning of each test class. In addition, I removed the tearDown() and the onSetUp() and onTearDown() methods. TestNG guarentees that multiple 'beforeTestClass' and 'beforeTestMethod' are executed descending through the inheritence tree. In addition, this should give users more power as they can now set dependencies of methods to guarentee order. In addition in the Transaction classes, the creation and rollback of the transactions area listed as 'before/afterTestMethod'.

I realize that this is simply a first cut and there will still need to be work done. I'd like to see this as part of 2.0 final, but understand if it can't make it. If you want me to redo the work with design input from you all, that'd be OK as well.


Affects: 2.0 M1

Attachments:

9 votes, 7 watchers

spring-projects-issues commented 17 years ago

Magnus Heino commented

What needs to be done for Spring to support TestNG? What should a patch include/look like to be accepted?

spring-projects-issues commented 17 years ago

Juergen Hoeller commented

TestNG support is now planned based on the test context framework that we're introducing in Spring 2.1 M4. Initially, we provide a SpringJUnit4ClassRunner for JUnit 4; we plan to provide a corresponding TestNG adapter later on.

Juergen

spring-projects-issues commented 17 years ago

Taras Tielkes commented

Any specific reasons for postponing TestNG support? 2.1 seems quite light on new features and TestNG is certainly in wide use these days. So - why hurry the release?

spring-projects-issues commented 17 years ago

Juergen Hoeller commented

We actually aim for providing a TestNG adapter for our new test context framework in time for the 2.1 release. I've checked with Sam that this is realistic; the TestNG support will be available in nightly snapshots right after the M4 release already. We just need to give people a chance to provide feedback before the RC1 release (scheduled for late September).

As for "quite light on new features" - I can't let you get away with that :-) I would rather argue that we have pretty significant new capabilities in there: Check out the M4 release in terms of the full scope of annotation-driven injection there (including support for 'qualifier' annotations), as well as the built-in AspectJ load-time weaving support etc. And of course, the new test context framework which is introduced in M4! We also aim for completing the overall Java 6 & Java EE 5 support in time for RC1, including JAX-WS support.

IMO, this is a pretty comprehensive release overall, in particular with respect to 'intimate' Java 5 / Java EE 5 support... Despite the Spring core remaining compatible with Java 1.4.2 there, this upcoming release is - from a user perspective - the point where Spring fully embraces Java 5. Spring 2.0 already fully supported Java 5, including the use of generics and annotations in application classes etc; now Spring gets a complete Java 5 annotation configuration model as a first-class option.

Juergen

spring-projects-issues commented 17 years ago

Sam Brannen commented

Support for TestNG is now provided via the "Spring TestContext Framework" that was added in Spring 2.1 M4 (see #7229).

Developers can directly use components of the TestContext framework (e.g., TestContextManager, TestExecutionListeners, etc.) to instrument TestNG-based test classes; however, Spring also provides abstract base support classes which developers may choose to extend as a convenience. These include AbstractTestNGSpringContextTests and AbstractTransactionalTestNGSpringContextTests, which are somewhat analogous to the legacy JUnit 3.8 support classes: AbstractSingleSpringContextTests, AbstractTransactionalDataSourceSpringContextTests, etc.

Consult the JavaDoc and the Testing chapter of the Spring Reference Manual for further details.

I encourage everyone to give the new TestNG support a try, and please let me know if you run into any issues or have any ideas for improvement.

Thanks,

Sam