You need to useduse code like this.which is following as:
use Magento\Framework\Event\ObserverInterface;
class TestObserver implements ObserverInterface
{
protected $_responseFactory;
protected $_url;
public function __construct(\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\UrlInterface $url)
{
$this->_responseFactory = $responseFactory;
$this->_url = $url;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$cartUrl = $this->_url->getUrl('checkout/cart/index');
$this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
exit;
}
}