/javascript/src/test/java/com/google/test/metric/javascript/JavascriptTestabilityTest.java
Java | 64 lines | 35 code | 9 blank | 20 comment | 0 complexity | 20916ac99ba6df9e2ebfceb037ebad4d MD5 | raw file
1/* 2 * Copyright 2007 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16package com.google.test.metric.javascript; 17 18import junit.framework.TestCase; 19 20/** 21 * Integration tests for javascript testability cost assessment 22 * 23 * @author alexeagle@google.com (Alex Eagle) 24 */ 25public class JavascriptTestabilityTest extends TestCase { 26 27 public void testExample() throws Exception { 28 FileRepository repository = new FileRepository(); 29 repository.addSourceFile("one.js", ""); 30 repository.addSourceFile("two.js", ""); 31 int overallCost = new JavascriptTestability(repository).calculateCost(); 32 assertEquals(0, overallCost); 33 } 34 35 public void testFunctionCost() throws Exception { 36 FileRepository repository = new FileRepository(); 37 repository.addSourceFile("one.js", "function a() {}"); 38 int overallCost = new JavascriptTestability(repository).calculateCost(); 39 assertEquals(0, overallCost); 40 } 41 42 public void testFunctionCost1() throws Exception { 43 FileRepository repository = new FileRepository(); 44 repository.addSourceFile("one.js", "function a() { var h = 'hello'; }"); 45 int overallCost = new JavascriptTestability(repository).calculateCost(); 46 assertEquals(0, overallCost); 47 } 48 49 public void testFunctionCost2() throws Exception { 50 FileRepository repository = new FileRepository(); 51 repository.addSourceFile("one.js", "function a() { return 'hello'; }"); 52 int overallCost = new JavascriptTestability(repository).calculateCost(); 53 assertEquals(0, overallCost); 54 } 55 56 public void testFunctionCost3() throws Exception { 57 FileRepository repository = new FileRepository(); 58 repository.addSourceFile("one.js", "h = 'hello'; function a() { return function() { h = '1'}}"); 59 int overallCost = new JavascriptTestability(repository).calculateCost(); 60 assertEquals(1, overallCost); 61 } 62 63 64}