Skip to content

Test item attributes

Ivan edited this page Dec 20, 2019 · 10 revisions

Test item attributes

There are @Attribute, @AttributeValue, @MultiKeyAttribute and @MultiValueAttribute annotations to attach required attributes to the TestItem.

All these annotations should be put inside @Attributes annotation that is parsed using AttributeParser method.

        @Test
	@Attributes(attributes = { @Attribute(key = "key", value = "value") })
	public void first() {
		Assert.assertEquals(1, 1);
	}

Result:

@Attribute annotation is required for attribute creation with both key and value specified.

@AttributeValue annotation is required for attribute creation with provided value and key=NULL.

        @Test
	@Attributes(attributeValues = { @AttributeValue(value = "value") })
	public void second() {
		Assert.assertEquals(1, 1);
	}

Result:

@MultiKeyAttribute annotation is required for multiple attributes with the same value and different keys creation. This annotation is used to simplify creation of multiple attribute with the same value (Instead of multiple @Attribute annotations only one @MultiKeyAttribute annotation is required).

        @Test
	@Attributes(multiKeyAttributes = { @MultiKeyAttribute(keys = { "k1", "k2" }, value = "v") })
	public void third() {
		Assert.assertEquals(1, 1);
	}

Result:

@MultiValueAttribute annotation is required for multiple attributes with the same key and different values creation. This annotation is used to simplify creation of multiple attribute with the same key (Instead of multiple @Attribute annotations only one @MultiValueAttribute annotation is required). It also contains Boolean field isNullKey to declare whether provided key should be NULL or not.

        //with provided key
        @Test
	@Attributes(multiValueAttributes = { @MultiValueAttribute(key = "k", values = { "v1", "v2" }) })
	public void fourth() {
		Assert.assertEquals(1, 1);
	}

        //with NULL key
        @Test
	@Attributes(multiValueAttributes = { @MultiValueAttribute(isNullKey = true, values = { "v1", "v2" }) })
	public void fifth() {
		Assert.assertEquals(1, 1);
	}

Result with key:
Result without key:

Test methods should be marked with @Attributes annotation with provided values so java-agent will retrieve method's annotation during execution and pass it into the AttributeParser.

You can combine multiple types of attributes within one @Attributes annotation:

        @Test
	@Attributes(attributes = { @Attribute(key = "key1", value = "value1"),
			@Attribute(key = "key2", value = "value2") }, multiKeyAttributes = { @MultiKeyAttribute(keys = { "k1", "k2" }, value = "v") })
	public void sixth() {
		Assert.assertEquals(1, 1);
	}

Result: