2017-07-27 107 views
0

我需要检查特定方法的多个变量值。在单元测试中测试多个变量值?

目前,我有以下几点:

describe('Example Test', function(){ 
    it('tests multiple input values', function(){ 
     expect(function(valOne)).toBe('testOne'); 
     expect(function(valTwo)).toBe('testTwo'); 
     expect(function(valThree)).toBe('testThree'); 

    }); 
}); 

其中,在未能返回以下消息:

Failures: 
1)Example Test tests multiple input values 
1.1) Expected 'testVal' to be 'testOne'. 

我知道我可以将它们一起在同一个想到声明如下:

describe('Example Test', function(){ 
    it('tests multiple input values', function(){ 
     expect(
      function(valOne) === 'testOne' && 
      function(valTwo) === 'testTwo' && 
      function(valThree) ==='testThree' 
     ).toBeTruthy(); 
    }); 
}); 

很显然,在这种情况下,失败消息只是表明错误整个状况的即将倒闭没有指明哪个特定条件(S)失败:

Failures: 
1)Example Test tests multiple input values 
1.1) Expected false to be truthy. 

正在使用多个except()语句来实现这一点的正确方法?

在单元测试中测试多个值的最佳做法是什么时候/如果失败我确切知道哪个条件/值失败?

+0

第一种方式有问题吗? – jonrsharpe

+0

@jonrsharpe不,没有问题,它的工作原理。我更想知道这是可接受的做法还是有更好的方法来做到这一点。 –

+1

我会说第一种方式更好,因为它更容易看到**在测试中错误发生在哪里** – 0mpurdy

回答

1

我会说第一种方式更好,因为它更容易看到其中在测试中发现错误。