Karma-Jasmine单元测试语法

时间:2017-09-06 19:04:11

标签: angular unit-testing jasmine karma-jasmine

您可以在同一个describe()文件中拥有多个.spec.ts吗?我不是在讨论嵌套describe

describe('First describe', () => {
  it();
 })
describe('Second describe', () => {
it();
});

在运行测试的任何时候这样做都有风险吗?我目前在describe中有4 .spec来测试不同的方案。大多数时候所有测试都通过。但是,即使预期值是正确的,一些测试也会随机失败。多个describe会导致某些问题吗?使它嵌套更好吗?这适用于angular4应用

1 个答案:

答案 0 :(得分:1)

是的,您可以在VOLUMES = ['119.823364', '121.143469'] P0 = ['4.97568007', '4.98494429'] P1 = [16.76591397, '16.88768068'] Xs = ['0.000000000000E+00', '3.333333333333E-01', '-4.090760942850E-01', '0.000000000000E+00', '3.333333333333E-01', '-4.093755657782E-01'] Ys = ['0.000000000000E+00', '-3.333333333333E-01', '-3.333333333333E-01', '0.000000000000E+00', '-3.333333333333E-01', '-3.333333333333E-01'] Zs = ['0.000000000000E+00', '-8.333333333333E-02', '-8.333333333333E-02', '0.000000000000E+00', '-8.333333333333E-02', '-8.333333333333E-02'] ATOMIC_NUMBERS = ['20', '6', '8', '20', '6', '8'] 中添加多个import sys import re import os initial_pattern = '^ FINAL OPTIMIZED GEOMETRY - DIMENSIONALITY OF THE SYSTEM 3$' middle_pattern = '^ CRYSTALLOGRAPHIC CELL ' end_pattern = '^ T = ATOM BELONGING TO THE ASYMMETRIC UNIT$' global N_atom_irreducible_unit N_atom_irreducible_unit = 3 VOLUMES = [] P0 = [] P2 = [] ATOMIC_NUMBERS = [] Xs = [] Ys = [] Zs = [] with open('g.out') as file: passed_mid_point = False for line in file: if re.match(initial_pattern, line): passed_mid_point = False print file.next() print file.next() print file.next() volume_line = file.next() print volume_line aux = volume_line.split() each_volume = aux[7] print each_volume VOLUMES.append(each_volume) if re.match(middle_pattern, line): passed_mid_point = True print line print file.next() parameters_line = file.next() aux = parameters_line.split() p0 = aux[0] p1 = aux[1] p2 = aux[2] p3 = aux[3] p4 = aux[4] p5 = aux[5] # print p0 print p2 P0.append(p0) P2.append(p2) print file.next() print file.next() print file.next() print file.next() if re.match(end_pattern, line): passed_mid_point = False elif passed_mid_point: # parse the coordinates print 'line2 =', line terms = line.split() print 'terms =', terms # print 'terms[1] =', terms[1] if terms and terms[1] == 'T': print terms[1] atomic_number = terms[2] print 'atomic_number = ', atomic_number ATOMIC_NUMBERS.append(atomic_number) x = terms[4] print 'x =', x Xs.append(x) y = terms[5] print 'y = ', y Ys.append(y) z = terms[6] print 'z = ', z Zs.append(z) print 'VOLUMES = ', VOLUMES print 'P0 = ', P0 print 'P2 = ', P2 print 'Xs = ', Xs print 'Ys = ', Ys print 'Zs = ', Zs print 'ATOMIC_NUMBERS = ', ATOMIC_NUMBERS ,因为它只是javascript函数。但是为了在测试中找到失败,你需要调试它。

您可以通过以下链接找到它: https://jasmine.github.io/2.1/introduction.html#section-It's_Just_Functions