Lively Kernel canvas
// this script is evaluated on world load
TestRunnerExample40
10000.43057188386593054Wikicontroltrue
10002.5993974948619445e-7Wikicontroltrue
BehaviorAdaptationmeasureandlogtheexecutiontimeofatestcase-Option1:changeexistingcode-Option2:Subclass-Option3:SeparateConcernasLayer5
TestRunnerrunTestCase:1
BehaviorAdaptationmeasureandlogtheexecutiontimeofeachtestinatestcaseProblem:....Solution:DynamicExtent
4
Problem:itmaymotivateandillustrateCOP,dynamicextent,global-andinstancespecificlayeractivation,butithasnothingtodowith"activeLayers"wennmansichschondieMühemachteineDomänemitBeispielensoeinzuführen,warumhörenwirvorherauf.WarumsolltenTestCasesnichtihreigenenesactiveLayershaben
5
10000.8817942284619398Wikicontroltrue
createLayer("TimeTestRunLayer");TimeTestRunLayer.setTimeOfTestRun=function(className,selector,time){if(!this.timeOfTestRuns)this.timeOfTestRuns={};if(!this.timeOfTestRuns[className])this.timeOfTestRuns[className]={};this.timeOfTestRuns[className][selector]=time;};TimeTestRunLayer.getSortedTimeOfTestRuns=function(){if(!this.timeOfTestRuns)return;varresult=[]Object.keys(this.timeOfTestRuns).each(function(eaClass){Object.keys(this.timeOfTestRuns[eaClass]).each(function(eaSelector){result.push([this.timeOfTestRuns[eaClass][eaSelector],eaClass,eaSelector])},this)},this);result=result.sort(function(a,b){returna[0]-b[0]});varstring="";result.each(function(ea){string=string+ea[0]+"\t"+ea[1]+">>"+ea[2]+"\n"})returnstring}layerClass(TimeTestRunLayer,TestCase,{runTest:function(proceed,selector){varstart=(newDate()).getTime();proceed(selector);vartime=(newDate()).getTime()-start;TimeTestRunLayer.setTimeOfTestRun(this.constructor.name,selector,time)}})layerClass(TimeTestRunLayer,TestRunner,{setResultOf:function(proceed,testObject){proceed(testObject);console.log("\nTimeTestRuns:\n"+TimeTestRunLayer.getSortedTimeOfTestRuns());TimeTestRunLayer.timeOfTestRuns={}//cleartherun...}})createLayer("DeployTimeTestRunLayer");enableLayer(DeployTimeTestRunLayer);disableLayer(DeployTimeTestRunLayer);//TimeTestRunLayershouldonlybeactive,whenthecontrollflowgoesthrouhrunTests...//DeployTimeTestRunLayerisusedtoseparatetheconcern,butnottospecifyadditionaldynamicbehaviorlayerClass(DeployTimeTestRunLayer,TestRunner,{runTests:function(proceed,buttonDown){withLayers([TimeTestRunLayer],function(){proceed(buttonDown)})}})>\" + ea[2] + \"\\n\"\n\t})\n\treturn string \n}\n\nlayerClass(TimeTestRunLayer, TestCase, {\n\trunTest: function(proceed, selector) {\n\t\tvar start = (new Date()).getTime();\t\n\t\tproceed(selector);\n\t\tvar time = (new Date()).getTime() - start;\n\t\tTimeTestRunLayer.setTimeOfTestRun(this.constructor.name, selector, time)\n\t}\n})\n\nlayerClass(TimeTestRunLayer, TestRunner, {\n\tsetResultOf: function(proceed, testObject) {\n\t\tproceed(testObject);\n\t\tconsole.log( \"\\nTime TestRuns:\\n\" + TimeTestRunLayer.getSortedTimeOfTestRuns());\n\t\tTimeTestRunLayer.timeOfTestRuns = {} // clear the run...\n\t}\n})\n\n\ncreateLayer(\"DeployTimeTestRunLayer\");\nenableLayer(DeployTimeTestRunLayer);\r\rdisableLayer(DeployTimeTestRunLayer);\r\n\n// TimeTestRunLayer should only be active, when the controll flow goes throuh runTests...\n// DeployTimeTestRunLayer is used to separate the concern, but not to specify additional dynamic behavior\n\nlayerClass(DeployTimeTestRunLayer, TestRunner, {\n\trunTests: function(proceed, buttonDown) {\n\t\twithLayers([TimeTestRunLayer], function() {\n\t\t\tproceed(buttonDown)\n\t\t})\n\t}\n})\n\n"]]>66truetruefalsetruetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
OriginalCodefalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
//newTestRunner().openIn(this.world())Config.loadTests=['TestFrameworkTests','FabrikTest','ConnectorTest'];varrequirements=Config.loadTests.collect(function(ea){return'Tests/'+ea+'.js'});if(requirements.length===0)requirements.push('TestFramework.js');require(requirements).toRun(function(currentModule){TestRunner.openIn();console.log('Testsloaded:.............................'+TestCase.allSubclasses().length);});module("TestRunnerExtensions").load()//meaningcodeWidget.subclass("TestRunner",{runTestCase:function(){vartestClassName=this.getSelectedTestClass();vartestCase=new(Class.forName(testClassName))();testCase.runAll(this);this.setResultOf(testCase);},})//1.mesureexecutiontimeofaTestCasecreateLayer("TimeTestLayer");layerClass(TimeTestLayer,TestRunner,{runTest:function(proceed){varstart=(newDate()).getTime();proceed(buttonDown);vartime=(newDate()).getTime()-start;console.log("TimetorunTestCase"+this.getSelectedTestClass()+"is"+time)}})//BehaviorAdaptationcanberealizedas://-subclassing//-globalactivation//-instancespecificlayeractivation//2.mesureeachtestexecutioninaTestCasecreateLayer("TimeEachTestLayer");layerClass(TimeEachTestLayer,TestCase,{runTest:function(proceed,selector){varstart=(newDate()).getTime();proceed(selector);vartime=(newDate()).getTime()-start;console.log("run"+this.constructor.name+"."+selector+":"+time)}})layerClass(TimeTestLayer,TestRunner,{runTest:function(proceed){withLayers([TimeEachTestLayer],function(){proceed(buttonDown)})}})1437
10000.38742048900000015Wikicontroltrue
10000.000001906837481167973Wikicontroltrue
10000.000026561398887587544Wikicontroltrue
10000.16058973808248156Wikicontroltrue
TestCaserunAllrunTest:
2
TestRunnerrunTestCase:1
dynamicextent
WiekönnteTestCaseactiveLayerssinnvollüberschreiben?1
100029.33706056857515Wikicontroltrue
Config.loadTests=['TestFrameworkTests','FabrikTest','ConnectorTest'];varrequirements=Config.loadTests.collect(function(ea){return'Tests/'+ea+'.js'});if(requirements.length===0)requirements.push('TestFramework.js');require(requirements).toRun(function(currentModule){TestRunner.openIn();console.log('Testsloaded:.............................'+TestCase.allSubclasses().length);});module("TestRunnerExtensions").load()TestRunner.prototype.buildView=function(extent){varpanel=PanelMorph.makePanedPanel(extent,[['testClassList',newRealListPane,newRectangle(0,0,1,0.6)],['runButton',function(initialBounds){returnnewButtonMorph(initialBounds)},newRectangle(0,0.6,0.5,0.05)],['runAllButton',function(initialBounds){returnnewButtonMorph(initialBounds)},newRectangle(0.5,0.6,0.5,0.05)],['resultBar',function(initialBounds){returnnewTextMorph(initialBounds)},newRectangle(0,0.65,1,0.05)],['failuresList',newTextListPane,newRectangle(0,0.7,1,0.3)],]);varmodel=this.getModel();//necessary?varself=this;vartestClassList=panel.testClassList;this.testClassListMorph=testClassList.innerMorph();this.testClassListMorph.itemPrinter=function(item){varstring="";if(self.testObject){vartime=self.testObject.result.getTimeToRun(item);if(time)string+="";}returnitem.toString()+string;};testClassList.connectModel(model.newRelay({List:'-TestClasses',Selection:'+SelectedTestClass'}),true);testClassList.innerMorph().focusHaloBorderWidth=0;varrunButton=panel.runButton;runButton.setLabel("RunTests");runButton.connectModel({model:self,setValue:"runTests"});varrunAllButton=panel.runAllButton;runAllButton.setLabel("RunAllTests");runAllButton.connectModel({model:self,setValue:"runAllTests"});//directlyusingthemorphforsettingthecolor--this.resultBar=panel.resultBar;this.resultBar.connectModel(model.newRelay({Text:'-ResultText'}));varfailuresList=panel.failuresList;failuresList.connectModel(model.newRelay({List:'-FailureList',Selection:'+Failure'}));//quickhackforbuildingstackListmodel.setFailure=model.setFailure.wrap(function(proceed,failureDescription){//FIXME:puthisintestResultproceed(failureDescription);if(!self.testObject){console.log('couldnotfindmytestObject:-(');return;}vari=self.testObject.result.failureList().indexOf(failureDescription);self.openErrorStackViewer(self.testObject.result.failed[i]);});returnpanel;}9truetruefalsetruetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
Screenshotforpaperhackfalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null54