1 package test.attributes;
2 
3 import org.testng.ITestContext;
4 import org.testng.annotations.BeforeClass;
5 import org.testng.annotations.Test;
6 
7 import java.util.Set;
8 
9 import junit.framework.Assert;
10 
11 public class AttributeTest {
12 
13   @BeforeClass
bc(ITestContext ctx)14   public void bc(ITestContext ctx) {
15     ctx.setAttribute("test", "1");
16   }
17 
18   @Test
f1(ITestContext ctx)19   public void f1(ITestContext ctx) {
20     Set<String> names = ctx.getAttributeNames();
21     Assert.assertEquals(1, names.size());
22     Assert.assertTrue(names.contains("test"));
23     Assert.assertEquals(ctx.getAttribute("test"), "1");
24     Object v = ctx.removeAttribute("test");
25     Assert.assertNotNull(v);
26     ctx.setAttribute("test2", "2");
27   }
28 
29   @Test(dependsOnMethods = "f1")
f2(ITestContext ctx)30   public void f2(ITestContext ctx) {
31     Set<String> names = ctx.getAttributeNames();
32     Assert.assertEquals(1, names.size());
33     Assert.assertTrue(names.contains("test2"));
34     Assert.assertTrue(ctx.getAttribute("test2").equals("2"));
35   }
36 
37 }
38