Friday 15 April 2016

Mean Bean: How to ignore a property

ConfigurationBuilder class provides ignoreProperty method; by using this we can set a property as ignored while testing. You can ignore any number of properties while testing.

Configuration config = new ConfigurationBuilder().iterations(55).ignoreProperty("firstName").ignoreProperty("lastName").build();

BeanTester beanTester = new BeanTester();
beanTester.testBean(Employee.class, config);


Above snippet tests Employee.class by ignoring the fields firstName and lastName.
public class Employee {
  private String firstName;
  private String lastName;
  private int id;
  private int age;
  private float salary;

  public String getFirstName() {
    return firstName.toUpperCase();
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName.toUpperCase();
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public int getAge() {
    return age;
  }

  public void setAge(int age) {
    this.age = age;
  }

  public float getSalary() {
    return salary;
  }

  public void setSalary(float salary) {
    this.salary = salary;
  }

}

import org.junit.Test;
import org.meanbean.test.BeanTester;
import org.meanbean.test.Configuration;
import org.meanbean.test.ConfigurationBuilder;

public class TestBean {

  @Test
  public void testEmployee() {
    Configuration config = new ConfigurationBuilder().iterations(55)
        .ignoreProperty("firstName").ignoreProperty("lastName").build();

    BeanTester beanTester = new BeanTester();
    beanTester.testBean(Employee.class, config);
  }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment