You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TestBox 2.1技术咨询:如何跳过整个目录或CFC测试文件

Answer

Great question! You have two solid options here depending on your needs—either exclude the entire /tests/lib directory from TestBox's test runs, or skip the specific utility component at the component level without modifying every method. Let's walk through both:

1. Exclude the /tests/lib directory entirely in TestBox configuration

TestBox lets you exclude specific paths from test execution, which is perfect if your /tests/lib folder is only for utility code (not actual test specs).

You can set this up in your root tests/TestBox.cfc file (the one that extends testbox.system.TestBox) by adding an excludePaths array in the configure method:

component extends="testbox.system.TestBox" {
    function configure() {
        // Define your actual test suites first
        testSuites = [
            { path = "/tests/specs", label = "Application Core Tests" }
        ];
        
        // Exclude the lib directory and all its contents
        excludePaths = [ "/tests/lib/**" ];
    }
}

The ** wildcard tells TestBox to ignore everything inside /tests/lib, including subdirectories. If you're using a standalone runner script (like tests/runner.cfm), you can pass the excludePaths directly to the run() method instead:

<cfset testbox = createObject("component", "testbox.system.TestBox")>
<cfset testbox.run(
    testSuites = [ "/tests/specs" ],
    excludePaths = [ "/tests/lib/**" ]
)>

2. Skip the individual utility component (without marking every method)

If you don't want to exclude the entire directory but just need to skip this specific HelperUtility.cfc, you can add a skip attribute directly to the component tag. TestBox respects this at the component level, so all test methods inside will be automatically skipped:

component skip=true {
    // All test methods in this component will be ignored
    function testHelperFunctionality() {
        // This method won't run—no need to add skip="true" here!
    }
}

You can also add a skipReason to document why the component is skipped, which will show up in test reports:

component skip=true skipReason="Utility component with no executable tests—only shared helper methods" {
    // ...
}

Which should you choose?

  • Use the directory exclusion if /tests/lib will only ever hold utility code (no real test specs) going forward—this keeps your test configuration clean and prevents accidental runs of non-test code.
  • Use the component-level skip if the directory might contain actual tests later, but you just need to ignore this one utility file right now.

内容的提问来源于stack exchange,提问作者Nick Petrie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:32:58