# Not able to add constraints from testcase for uvm\_object class

**URL:** <https://verificationacademy.com/forums/t/not-able-to-add-constraints-from-testcase-for-uvm-object-class/31057>\
**Category:** UVM\
**Tags:** UVM, randomization-constraints, Systme-verilog-Constraints\
**Created:** [September 23, 2015, 10:10am UTC](https://verificationacademy.com/forums/t/not-able-to-add-constraints-from-testcase-for-uvm-object-class/31057 "2015-09-23T10:10:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashwanth\_madisetty](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/y/ba8739/32.png) [@yashwanth\_madisetty](https://verificationacademy.com/forums/u/yashwanth_madisetty)\
**Post date:** [September 23, 2015, 10:10am UTC](https://verificationacademy.com/forums/t/not-able-to-add-constraints-from-testcase-for-uvm-object-class/31057/1 "2015-09-23T10:10:14Z")

</div>

Hi All,

I have a config class…

class config extends uvm\_object;

rand int rate;

endclass

class my\_test extends uvm\_test;  
config cfg;  
cfg=new();  
constraint bit\_rate\_1{cfg.rate==1;} //This constraint is not working …  
assert(cfg.randomize()); //doing it in build phase  
endclass

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 23, 2015, 2:17pm UTC](https://verificationacademy.com/forums/t/not-able-to-add-constraints-from-testcase-for-uvm-object-class/31057/2 "2015-09-23T14:17:54Z")

</div>

The constraint bit\_rate\_1 is for the my\_test class - it would only work if you randomized my\_test. You need to either extend the class config with that constraint and construct the extended class in my\_test, or use the randomize ‘with’ clause.
