My goal is to generate a test method (automatically if we can say so). To do this, I need to send to a method that I named writeTestMethod., two parameters: the method I want to generate its test method from and a set of values as the second. Once I send this, writeTestMethod will generate me the test method in which there are the assertions.
In the test method, I must be able to retrieve its class from the send method as a parameter. Once done, I initialize this class with its default constructor. And the second parameter is a set of values, with this set of values, I will initialize a new object of the same class but this time using the values. and at the level of the assertions, I will test if the two are equal.
I have a method that allows me to build the name of a test method but I can't write in it.
buildSelectorFor: aMethod
^ String streamContents: [:i || capitalize |
capitalize := true.
i << 'test'.
aMethod selector do: [:charactar |
charactar= $:
ifTrue: [ capitalize := true ]
ifFalse: [ capitalize
ifTrue: [
capitalize := false.
i << charactar asUppercase. ]
ifFalse:[ i << charactar ]]]]
so if I execute this method with this for example:
buildSelectorFor:Car>>#speed:mark:
I get this:
testSpeedMark
my goal is to get something like
testSpeedMark
self assert:....equals:...
I added a method writeTestMethod.
writeTestMethod: aMethod with: anObject
^(self buildTestSelectorFor: aMethod),'
|classMethod setter instObject method|
classMethod := aMethod methodClass.
setter := (classMethod allSelectorsInProtocol: #setter) asArray.
instObject := classMethod new.
(setter with: anObject do: [:set :ivar | instObject perform: set with: ivar]).
self assert: instObject class equals: (classMethod new) class.'
I don't know how to integrate the parameters of writetestMethod in the code I want to generate

Your question seems to indicate that you have a parametric template for creating source code, in this case, source code of tests methods, and a way to generate data that should be tested with the resulting methods.
Write one method that receives the required parameters and answers with the source code of the desired method (it looks like you already know how to do this, see 3 bellow though)
Install the method in
aClass(a subclass ofTestCasewhose name I don't know). To do this, you can useaClass compile: source, wheresourcewas obtained in step 1.Add an ivar
datato your testing class and a setter for it. Make sure that the source code generated in step 1 operates on the ivardata.For each piece of data you happen to generate create an instance of your testing class, set the ivar
dataaccordingly and add the test to a newly createdTestSuite(useTestSuite >> named:for this). Here you can useTestSuite >> addTest:.Run your suite with
TestSuite >> run.To get rid of automatically created tests, should you want to do that, send
removeSelector:to your testing class.