PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/javascript/src/test/java/com/google/test/metric/javascript/JavascriptTestabilityTest.java

http://testability-explorer.googlecode.com/
Java | 64 lines | 35 code | 9 blank | 20 comment | 0 complexity | 20916ac99ba6df9e2ebfceb037ebad4d MD5 | raw file
Possible License(s): Apache-2.0
  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. */
  16. package com.google.test.metric.javascript;
  17. import junit.framework.TestCase;
  18. /**
  19. * Integration tests for javascript testability cost assessment
  20. *
  21. * @author alexeagle@google.com (Alex Eagle)
  22. */
  23. public class JavascriptTestabilityTest extends TestCase {
  24. public void testExample() throws Exception {
  25. FileRepository repository = new FileRepository();
  26. repository.addSourceFile("one.js", "");
  27. repository.addSourceFile("two.js", "");
  28. int overallCost = new JavascriptTestability(repository).calculateCost();
  29. assertEquals(0, overallCost);
  30. }
  31. public void testFunctionCost() throws Exception {
  32. FileRepository repository = new FileRepository();
  33. repository.addSourceFile("one.js", "function a() {}");
  34. int overallCost = new JavascriptTestability(repository).calculateCost();
  35. assertEquals(0, overallCost);
  36. }
  37. public void testFunctionCost1() throws Exception {
  38. FileRepository repository = new FileRepository();
  39. repository.addSourceFile("one.js", "function a() { var h = 'hello'; }");
  40. int overallCost = new JavascriptTestability(repository).calculateCost();
  41. assertEquals(0, overallCost);
  42. }
  43. public void testFunctionCost2() throws Exception {
  44. FileRepository repository = new FileRepository();
  45. repository.addSourceFile("one.js", "function a() { return 'hello'; }");
  46. int overallCost = new JavascriptTestability(repository).calculateCost();
  47. assertEquals(0, overallCost);
  48. }
  49. public void testFunctionCost3() throws Exception {
  50. FileRepository repository = new FileRepository();
  51. repository.addSourceFile("one.js", "h = 'hello'; function a() { return function() { h = '1'}}");
  52. int overallCost = new JavascriptTestability(repository).calculateCost();
  53. assertEquals(1, overallCost);
  54. }
  55. }