I have created a module and its working fine.

I want to write Unit test for it(i know that i should write unit test before writing code).

I tried this way , but i am not clear about it.

My Block File - (app\code\Mycompany\Careers\Block\Index)

namespace Mycompany\Careers\Block\Index;
class Index extends \Magento\Framework\View\Element\Template {

protected $_careersFactory;
  public function __construct(
    \Magento\Catalog\Block\Product\Context $context, 
    \Mycompany\Careers\Model\CareersFactory $careersFactory,
    array $data = []) {
    $this->_careersFactory = $careersFactory;
    parent::__construct($context, $data);


 protected function _prepareLayout()
    return parent::_prepareLayout();

* this function return all the jobs currently active in careers extension
  public function getAllCareers(){

    $Careers = $this->_careersFactory->create();
    $collection = $Careers->getCollection();

    return $collection->setOrder('sort_order','ASC');
  }//End of function getHomepageBanners

I created my unit test file like this file IndexTest.php - (app\code\Mycompany\Careers\Test\Unit\Block)

namespace Mycompany\Careers\Test\Unit\Block;
use Mycompany\Careers\Block\Index\Index;

class IndexTest extends \PHPUnit_Framework_TestCase
   protected $careers;

   public function setUp()
    $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
    $this->careers = $objectManager->getObject('Mycompany\Careers\Block\Index\Index');


   public function testGetAllCareers(){

      //What should i want to write here?


for this what should i write in side my testGetAllCareers() method?. What else i want to do for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.