【问题标题】:Run Jasmine tests on a view in a MVC project.在 MVC 项目中的视图上运行 Jasmine 测试。
【发布时间】:2014-10-15 21:38:03
【问题描述】:

我正在尝试在 Visual Studio 2013 和 Jasmine 测试中设置使用 Chutzpah 的测试。我可以使用固定装置加载 html 文件,据我了解,这些固定装置将放在默认线束文件的主体中。

相反,我想为实际生产代码创建测试,并基本上在我们用于所有视图的母版页上运行一些测试,以检查所有内容是否已正确加载、看起来是否正常等。

有什么明显的方法可以做到这一点吗?

【问题讨论】:

    标签: testing model-view-controller jasmine jasmine-jquery


    【解决方案1】:

    听起来您正在寻找比单元测试更多的功能样式测试。如果您仍然想为此使用 PhantomJS 无头浏览器,我建议您使用 CasperJS,它提供了一种自动化网页导航和断言的简单方法。

    例如,hear 是 their documentation 在测试中的摘录:

    casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
        casper.start("http://www.google.fr/", function() {
            test.assertTitle("Google", "google homepage title is the one expected");
            test.assertExists('form[action="/search"]', "main form is found");
            this.fill('form[action="/search"]', {
                q: "casperjs"
            }, true);
        });
    
        casper.then(function() {
            test.assertTitle("casperjs - Recherche Google", "google title is ok");
            test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
            test.assertEval(function() {
                return __utils__.findAll("h3.r").length >= 10;
            }, "google search for \"casperjs\" retrieves 10 or more results");
        });
    
        casper.run(function() {
            test.done();
        });
    });
    

    【讨论】:

    • 我自己也得出了同样的结论,并计划研究 Selenium 和 NUnit,但 CasperJS 看起来非常适合我的需求 :) 感谢您的提示! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    相关资源
    最近更新 更多