/hudson-test-framework/src/main/java/org/jvnet/hudson/test/TestExtension.java

http://github.com/hudson/hudson · Java · 72 lines · 15 code · 4 blank · 53 comment · 0 complexity · ed283d5b190e3a51c51ce9e597694c0b MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2010, Sun Microsystems, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package org.jvnet.hudson.test;
  25. import hudson.Extension;
  26. import net.java.sezpoz.Indexable;
  27. import java.lang.annotation.Documented;
  28. import java.lang.annotation.Retention;
  29. import java.lang.annotation.Target;
  30. import static java.lang.annotation.ElementType.*;
  31. import static java.lang.annotation.RetentionPolicy.RUNTIME;
  32. /**
  33. * Works like {@link Extension} except used for inserting extensions during unit tests.
  34. *
  35. * <p>
  36. * This annotation must be used on a method/field of a test case class, or an nested type of the test case.
  37. * The extensions are activated only when the outer test class is being run.
  38. *
  39. * @author Kohsuke Kawaguchi
  40. * @see TestExtensionLoader
  41. */
  42. @Indexable
  43. @Retention(RUNTIME)
  44. @Target({TYPE, FIELD, METHOD})
  45. @Documented
  46. public @interface TestExtension {
  47. /**
  48. * To make this extension only active for one test case, specify the test method name.
  49. * Otherwise, leave it unspecified and it'll apply to all the test methods defined in the same class.
  50. *
  51. * <h2>Example</h2>
  52. * <pre>
  53. * class FooTest extends HudsonTestCase {
  54. * public void test1() { ... }
  55. * public void test2() { ... }
  56. *
  57. * // this only kicks in during test1
  58. * &#64;TestExtension("test1")
  59. * class Foo extends ConsoleAnnotator { ... }
  60. *
  61. * // this kicks in both for test1 and test2
  62. * &#64;TestExtension
  63. * class Bar extends ConsoleAnnotator { ... }
  64. * }
  65. * </pre>
  66. */
  67. String value() default "";
  68. }