标签: testcase

Django UrlResolver,在运行时添加url进行测试

我正在寻找一些测试,但我还不太熟悉,URLResolver但我想快速解决这个问题.

在a中TestCase,我想在解析器中添加一个URL,以便我可以使用Client.get('/url/')它并将其与之分开urls.py.

django url unit-testing testcase

28
推荐指数
3
解决办法
7323
查看次数

NUnit在包含数组时无法识别TestCase

这是非常简单但令人烦恼的行为,我遇到了NUnit:

我有一些像这样的测试:

[Test]
[TestCase( 1, 2, "hello" )]
[TestCase( 3, 5, "goodbye" )]
public void MyClass_MyMethod( int a, int b, string c )
{
    Assert.IsTrue( a < b );
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,在ReSharper NUnit窗格中,我可以看到每个TestCase在结果中获得自己的响应.

我有第二个看起来像这样的TestCase:

[Test]
[TestCase( 1, 2, new long[] { 100, 200 })]
[TestCase( 5, 3, new long[] { 300, 500 })]
public void MyClass_MyOtherMethod( long a, long b, long[] bunchOfNumbers )
{
   Assert.IsTrue( a < b );
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我看到了这个:

一个或多个子测试有错误Exception没有堆栈跟踪

public void MyClass_MyOtherMethod(5,3,System.Int64 [])失败

与我的其他测试不同的是,它将每个TestCase抽取为测试列表上的一个单独的复选框,而这一个没有显示,我没有详细信息,直到我在调试器中运行它出现了什么问题以及在哪里.我有点担心这个测试在构建机器上的表现.有谁知道发生了什么,为什么?

c# nunit unit-testing testcase

28
推荐指数
2
解决办法
2万
查看次数

编写可重用(参数化)unittest.TestCase方法

可能重复:
如何在python中生成动态(参数化)单元测试?

我正在使用unittest包编写测试,我想避免重复代码.我将进行一些测试,这些测试都需要一个非常类似的方法,但每次只有一个值不同.一个简单而无用的例子是:

class ExampleTestCase(unittest.TestCase):

    def test_1(self):
        self.assertEqual(self.somevalue, 1)

    def test_2(self):
        self.assertEqual(self.somevalue, 2)

    def test_3(self):
        self.assertEqual(self.somevalue, 3)

    def test_4(self):
        self.assertEqual(self.somevalue, 4)
Run Code Online (Sandbox Code Playgroud)

有没有办法编写上面的例子,而不是每次都重复所有的代码,而是编写一个通用的方法,例如

    def test_n(self, n):
        self.assertEqual(self.somevalue, n)
Run Code Online (Sandbox Code Playgroud)

告诉unittest用不同的输入尝试这个测试?

python unit-testing testcase parameterized-unit-test

26
推荐指数
2
解决办法
1万
查看次数

是否有一个等同于NUnit的testcase属性的JUnit?

我已经搜索了JUnit测试用例,它提出了一些看起来实现起来要复杂得多的东西 - 你必须创建一个扩展测试用例然后调用的新类:

public class MathTest extends TestCase {
    protected double fValue1;
    protected double fValue2;

    protected void setUp() {
       fValue1= 2.0;
       fValue2= 3.0;
    }
 }

public void testAdd() {
   double result= fValue1 + fValue2;
   assertTrue(result == 5.0);
}
Run Code Online (Sandbox Code Playgroud)

但我想要的是非常简单的东西,比如NUnit测试用例

[TestCase(1,2)]
[TestCase(3,4)]
public void testAdd(int fValue1, int fValue2)
{
    double result= fValue1 + fValue2;
    assertIsTrue(result == 5.0);
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在JUnit中这样做?

junit nunit unit-testing testcase testcaseattribute

25
推荐指数
5
解决办法
4716
查看次数

Laravel 4在TestCase中未发现任何测试

我在使用phpunit时遇到了一些问题.当我执行测试时,phpunit给我这些警告:

1)警告在"Illuminate\Foundation\Testing\TestCase"类中没有找到测试.

2)警告在"TestCase"类中没有找到测试.

但是我想忽略这些文件,因此phpunit不会尝试从它们运行测试.

怎么做?

phpunit ignore testcase

24
推荐指数
2
解决办法
7908
查看次数

比较django TestCase中的查询集

我有一个非常简单的观点如下

def simple_view(request):
    documents = request.user.document_set.all()
    return render(request, 'simple.html', {'documents': documents})
Run Code Online (Sandbox Code Playgroud)

为了在我的测试用例中测试上面的视图,我有以下方法出错.

Class SomeTestCase(TestCase):
    # ...
    def test_simple_view(self):
        # ... some other checks
        docset = self.resonse.context['documents']
        self.assertTrue(self.user.document_set.all() == docset) # This line raises an error
    # ...
Run Code Online (Sandbox Code Playgroud)

我得到的错误是AssertionError: False is not true.我尝试打印两个查询集,两者完全相同.False当两个对象相同时,为什么会返回?有任何想法吗 ?

目前为了克服这一点,我使用了一个讨厌长度的讨厌的黑客如下:

ds1, ds2 = self.response.context['documents'], self.user.document_set.all()
self.assertTrue(len([x for x in ds1 if x in ds2]) == len(ds1) == len(ds2)) # Makes sure each entry in ds1 exists in ds2
Run Code Online (Sandbox Code Playgroud)

django compare django-queryset testcase

18
推荐指数
2
解决办法
8504
查看次数

Jira作为测试用例管理工具

我已经审查了几个可用于Jira的测试用例管理解决方案,例如:

我想知道是否有可能进一步扩展这个测试用例管理解决方案.我正在寻找一个Jira解决方案:

  • 要求
  • 测试用例(符合要求)
  • 测试报告(根据测试用例)

上面发布的链接仅忽略"要求"部分,仅关注测试用例和测试报告.我之前使用的每个测试用例管理工具都具有HP QualityCenter等功能.

是否有可能在Jira实现这一目标?

TIA

jira testcase

16
推荐指数
3
解决办法
3万
查看次数

@After,@之前没有在testcase中工作

我已经开始测试,现在我想使用@After,@Before@Test但我的应用程序只运行的@Before方法和控制台提供输出

之前

但是,如果我删除@After@Before运行@Test.我的代码在这里:

public class TestPractise extends AbstractTransactionalDataSourceSpringContextTests{

    @Before
    public void runBare(){
        System.out.println("before");
    }

    @Test
    public void testingMethod(){
        System.out.println("testing");
    }

    @After
    public void setDirty(){
        System.out.println("after");
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么不@After,@Test@before同时工作?

java junit testcase

14
推荐指数
5
解决办法
3万
查看次数

多次运行PHPUnit测试用例

我正在寻找一种如何使用不同的设置多次运行测试用例的方法.

我正在测试一个数据库访问类(几十种测试方法),并希望在"正常模式"下测试它,然后在"调试模式"下测试它.两种模式都必须产生相同的测试结果.

在测试用例设置中是否有可能这样做?或者重写run()方法?我当然不想写两次测试:)

谢谢

编辑:GOT IT!

public function run(PHPUnit_Framework_TestResult $result = NULL)
{
    if ($result === NULL) {
        $result = $this->createResult();
    }

    /**
     * Run the testsuite multiple times with different debug level
     */
    $this->debugLevel = 0;
    print "Setting debug level to: " . $this->debugLevel . PHP_EOL;
    $result->run($this);

    $this->debugLevel = 8;
    print "Setting debug level to: " . $this->debugLevel . PHP_EOL;
    $result->run($this);

    $this->debugLevel = 16;
    print "Setting debug level to: " . $this->debugLevel . PHP_EOL;
    $result->run($this);

    return $result;
}

public …
Run Code Online (Sandbox Code Playgroud)

php phpunit testcase

13
推荐指数
2
解决办法
3184
查看次数

如何有效地为我的Android应用程序实现MVVM设计模式,这也将简化测试用例的编写?

我正计划为我的Android应用程序实现MVVM架构设计模式.我在网上看到它将帮助我实现有效的关注点分离,并轻松编写数据模型,UI等测试用例.需要一些见解/建议.

android mvvm testcase

12
推荐指数
1
解决办法
2万
查看次数