richard.herbert
04/14/2023, 11:38 AMcfhttp
call so I can test the subsequent processing of the data returned.
I've mocked the component with createMock()
and mocked the result with $property()
but when I run my test the API is called, which of course fails, because I'm not giving it all the info it needs to run.
Is this type of thing impossible to test unless I wrap the API call in its own method, so I can mock that out completely? I'm cool with that if it's the only solution, I just wanted to have some tests in place before I did any refactoring.
Opinions welcomed.Adam Cameron
<cfhttp>
call, precisely for this; then you mock that out.Adam Cameron
expect(myQuery).toHaveKey("current_date")
Where current_date
is a column of the query.
Looking into it, it's here: https://github.com/Ortus-Solutions/TestBox/blob/v4.5.0/system/Assertion.cfc#L382
len( arguments.message ) ? arguments.message : "The key(s) [#arguments.key#] does not exist in the target object. Found keys are [#structKeyArray( arguments.target ).toString()#]"
It's barfing on structKeyArray( arguments.target )
.
The surprising thing to me is that this works on Lucee. structKeyArray
should not accept a query š
The docs clearly say it takes a struct: https://docs.lucee.org/reference/functions/structkeyarray.html
Why does Lucee do this shit? šJ
04/24/2023, 2:10 PMif( loginAttempt > 3) {
cfthrow message="your account may be locked."
}
So, In the testbox side how can I able to achieve the expectations? Could you please help me?bockensm
04/26/2023, 6:31 PMreporter=mintext outputFile=/path/to/file.xml outputFormats=junit
but it doesn't write the file. I'm using this in GitLab CI so I want to see the mintext results when viewing the pipeline, but GitLab also wants junit XML for one if its features to show when tests started failing.lmajano
05/05/2023, 1:19 PMevagoras
05/11/2023, 2:13 PMaliaspooryorik
asyncAll
when doing given > when > then.lmajano
06/15/2023, 2:57 PMAdam Cameron
lmajano
07/27/2023, 4:26 PMbe.
Welcome to the world of TestBox Modules!! Hierarchical Modules for Testing Pleasures: https://ortussolutions.atlassian.net/browse/TESTBOX-377
Please try it out and let me know how we can improve it!lmajano
08/01/2023, 10:36 AMaliaspooryorik
richard.herbert
08/09/2023, 4:40 PM/tests
now respond with...tony
12/07/2023, 9:09 PMDirk
01/30/2024, 10:59 AMAdam Brunt
02/07/2024, 6:01 PMTim Garver
02/15/2024, 6:12 PMTim Garver
02/15/2024, 6:30 PMTim
05/01/2024, 9:49 PMvar testValue = '{abc:"def"}';
var actualValue = myComponent.getFormattedText(testValue);
expect(actualValue).toInclude(EncodeForXML(testValue));
And that's "failing" because
The needle [{abc:"def"}] was not found in [<?xml version="1.0" encoding="UTF-8"?><record><datum key="id">{abc:"def"}</datum></record>I think it's worth noting that getFormattedText also runs testValue through EncodeForXML under the hood. So it's especially a mystery to me why it comes out nice on one side, but not on the other. Why is EncodeForXML feeling a need to encode the braces and quotes in one string, but not the other, causing them to not match?
Dave Merrill
05/11/2024, 11:29 AMBrent
05/21/2024, 3:50 PMchris-schmitz
06/03/2024, 12:00 PMonSpecEnd()
, I tested the method by calling it directly and the file was created as expected. I then went on and passed the listener CFC to testbox: testbox.run( callbacks=myLstener )
, but, it seems in this case onSpecEnd()
is not executed.
So maybe I am misunderstanding the concept and purpose of listeners? Unfortunately the Testbox docs don't say much about it, can somebody please tell me where to find more information or how to tackle my initial problem (tests sometimes failing, sometimes passing)? Thank you!Brent
06/11/2024, 9:15 PMAndras Nagy
06/20/2024, 5:30 AMFunction 'getComponentMetadata' not found
error for a lot of things I'm doing so this might be a generic error.
private function runTests() {
var javaSystem = createObject( "java", "java.lang.System" );
var exerciseRoot = javaSystem.getProperty( "user.dir" );
var testCFC = ArrayFirst( DirectoryList( path = exerciseRoot, filter = "*Test.cfc" ) );
var testRunner = new testbox.system.TestBox( testCFC );
var testData = testRunner.runRaw().getMemento();
println( testData );
// Set proper exit code
if( testData.totalFail || testData.totalError ) {
setExitCode( 1 );
}
}
Brent
06/24/2024, 11:20 PMbeforeAll()
to instantiate the component. My question is what is recommended for initializing an environment (populating and setting up needed global settings. i.e. found in Application.cfc) in the tests?
Example:
component extends="testbox.system.BaseSpec" {
function beforeAll(){
// I could setup things like this, but is there a better way?
application.dsn = "myDsn";
// Is there a way to reference what is set in Application.cfc - Can I just reuse what is already set in Application.cfc? (there are a lot of global vars set...)
// should I replicate Application.cfc var settings in the tests/Application.cfc (this feels wrong and maintenance problem prone)
// instantiate my component with necessary dependencies injected
myComponent = createObject('component', 'some.cool.Component').init(
dsn=application.dsn,
someKey=application.someKey,
otherInjectedComponent=application.instantiatedOtherComponent,
//etc....
)
}
function afterAll(){
// Do I need to do anything here?
}
describe("component tests", function() {
it("can compile", function() {
// referencing the component instance I created in beforeAll
expect(myComponent).toBeComponent();
});
});
}
Brent
06/26/2024, 1:40 AMsuper.beforeAll()
or super.afterAll()
in test bundles referenced in documentation and examples I'm reading that inherit from a Base Test Class (that inherits from the Testbox Base Spec).
Can someone explain to me what this means:
"This also helps parent classes enforce their setup methods are called by annotating the methods with @beforeAll
. No more forgetting to call super.beforeAll()
!"
- from this page: https://testbox.ortusbooks.com/in-depth/life-cycle-methods/annotations
I am not doing this (not calling super.beforeAll etc, anywhere), but my tests are working fine. Am I missing something or should I be calling that somewhere? When and where do you need to call the super.[LifeCycleMethods]()
?
My class inheritance:
testbox.system.BaseSpec
-> myBaseTestClass (initializes application variables/test setup and does not call super.beforeEach etc.)Brent
07/02/2024, 8:39 PMsetSomeProp()
method that exists on it?Brent
07/03/2024, 5:01 PMmockBox.createStub(extends="path.to.my.s3service");
That will create a fake S3 service that mirrors the interface etc of my service but not actually do anything, right?
Do I need to call init() on that as well to instantiate it?Brent
07/03/2024, 8:19 PM