【问题标题】:Executing Laravel Unit Tests externally在外部执行 Laravel 单元测试
【发布时间】:2017-06-15 06:28:16
【问题描述】:

我在我的 Laravel 项目中编写了一些单元测试,并尝试通过第三方应用程序执行它们。我可以使用 phpunit 在命令行中执行这些测试,但我的要求是在外部运行它们(以自动化)。这有可能吗?我的自定义类/Laravel 辅助类在外部运行时似乎无法访问。

use App\ZZZ\Scrape;
use App\ZZZ\Theme1;
use App\ZZZ\Theme2;

class ScrapeTest extends TestCase
{
protected static $scrape;
protected static $sxe;
protected static $theme;
protected static $url;
protected static $section;
protected static $extArray;
protected static $intArray;
protected static $safetyArray;
protected static $perfArray;
protected static $output;

public static function setUpBeforeClass()
{
    Config::set('aws.s3Path', 'zz/test/');
    self::$url = "http://www.testsite.com.au";
    self::$section = "testSection";
    self::$scrape = new Scrape(self::$url, self::$section);
    self::$scrape->html = self::$scrape->getHTML();
    self::$sxe = self::$scrape->getSimpleXmlElement();

    if(self::$scrape->isDarkTheme(self::$sxe))
    {
        self::$theme = new Theme1(self::$url,self::$section);
    }
    else
        self::$theme = new Theme2(self::$url,self::$section);

    self::$output = new stdClass();

    //exterior features
    self::$extArray = self::$theme->getFeatureDetails(self::$sxe, "exterior");
    self::$output->ExteriorFeatures = new stdClass();
    self::$output->ExteriorFeatures->Feature = self::$extArray;

    //interior features
    self::$intArray = self::$theme->getFeatureDetails(self::$sxe, "interior");
    self::$output->InteriorFeatures = new stdClass();
    self::$output->InteriorFeatures->Feature = self::$intArray;


}

public function testGetLeadingText()
{
    $result = self::$scrape->getLeadingText(self::$sxe);
    $this->assertNotNull($result, "No leading text");
}

public function testFetchColours()
{
    $result = self::$scrape->FetchColours();
    $this->assertNotNull($result, "Error with decoding colour API");
    $this->assertInternalType('array', $result->data, "FetchAPI  output is not an array");
    $this->assertNotSame(null, $result->data, "FetchAPI  output is an empty array");
 }  

}

我得到的一些错误:

在 C:...\ScrapeTest.php 中找不到类“TestCase”

在 C:...\ScrapeTest.php 中找不到类“配置”

在 C:...\ScrapeTest.php 中找不到类 'App\ZZZ\Scrape' ...

非常感谢任何帮助。提前致谢。

【问题讨论】:

  • 你能告诉我们你的UnitTest.php内容
  • 感谢您的帮助。我得到的错误之一:致命错误:在 C:\...\ScrapeTest.php 中找不到类 'App\ZZZ\Scrape'。它也抱怨 TestCase 类。如果您需要更多详细信息,请告诉我。
  • 我已经更新了我的问题
  • 有人可以帮忙吗?

标签: laravel phpunit


【解决方案1】:

您的测试文件似乎不完整。

您需要声明测试类所在的命名空间以及测试用例所在的命名空间。

例如。如果在您的情况下测试用例在 Tests 中,并且在 Tests\ZZZ 中的测试文件,则在文件开头使用它。

namespace Tests\ZZZ;

use Tests\TestCase;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-02
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    • 2016-08-25
    • 1970-01-01
    相关资源
    最近更新 更多