标签: testcase

如何为返回对象的方法编写测试用例

我有一个方法,其返回类型是对象。我如何为此创建一个测试用例?我如何提及结果应该是一个对象?

例如:

public Expression getFilter(String expo)
{
    // do something
    return object;
}
Run Code Online (Sandbox Code Playgroud)

java junit object testcase

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

如何有效地测试这个 Django 模型?

我正在为一个网站构建一个身份验证系统,我之前没有 Django 的测试经验。我写了一些基本的测试。

该模型,

class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(max_length=25, unique=True, error_messages={
        'unique': 'The username is taken'
    })
    first_name = models.CharField(max_length=60, blank=True, null=True)
    last_name = models.CharField(max_length=60, blank=True, null=True)
    email = models.EmailField(unique=True, db_index=True, error_messages={
        'unique': 'This email id is already registered!'
    })

    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)

    date_joined = models.DateTimeField(auto_now_add=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username',]


    objects = UserManager()

    def get_full_name(self):
        return ' '.join([self.first_name, self.last_name])

    def get_short_name(self):
        return self.email

    def __unicode__(self):
        return self.username
Run Code Online (Sandbox Code Playgroud)

和模特经理,

class UserManager(BaseUserManager):
    def create_user(self, email, password=None, …
Run Code Online (Sandbox Code Playgroud)

python testing django testcase django-testing

3
推荐指数
1
解决办法
903
查看次数

如何调用具有多个参数的测试方法(NUnit)

我的测试方法如下所示:

public static List<Something> Generator() {
return A.GenerateObjects();
}

[Test, TestCaseSource(nameof(Generator))]
    public void DoSomething(Something abc) {/*do something*/}
Run Code Online (Sandbox Code Playgroud)

该代码运行良好,并为列表中的每个对象生成一个单元案例。

我想在方法中包含另一个参数,例如:

public void DoSomething(Something abc, string def)
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用这些行,但它不起作用:

public static object[] Case =
    {
        new object[]
        {
            A.GenerateObjects(),
            someStrings
        }
    };
Run Code Online (Sandbox Code Playgroud)

也许使用循环函数迭代列表而不是直接调用方法(GenerateObjects())?我也不明白 Nunit 如何仅使用 TestCaseSource(nameof(Generator)) 直接识别列表中的对象

提前致谢!

c# nunit testcase testcasesource

3
推荐指数
1
解决办法
4308
查看次数

如何在角度组件的测试中模拟 @INPUT 值

在我的 angular 应用程序中,我正在为具有 @Input 值的组件编写测试用例。如何模拟 @Input 值。主组件的 testSave() 方法使用子组件的 InputObject 的 id。当我运行测试用例时,它说 undefined 是“this.subComponent.InputObject.id;”处的一个对象

export class SubComponent implements OnInit {
  @Input() inputObj: InputObject;
}

export class MainComponent implements OnInit {
  @Input() subComponent: SubComponent;

  testsave() {
  this.subComponent.InputObject.id;
  }
}

export class InputObject {
  contructor(id:string, name: string)
}
Run Code Online (Sandbox Code Playgroud)

测试用例:

 it('should save', fakeAsync(()  => {
//     const event: MockEvent = new MockEvent();
//     fixture = TestBed.createComponent(MainComponent);
//     component = fixture.componentInstance;
 });
Run Code Online (Sandbox Code Playgroud)

input mocking testcase angular

3
推荐指数
1
解决办法
5465
查看次数

有哪些方法可以发现测试用例

所有,

我是开发人员,但想了解有关测试过程和方法的更多信息.我相信这有助于我编写更加可靠的代码,因为它改进了我可以在将产品交付给测试团队之前使用我的单元测试进行测试的情况.我最近开始研究软件项目的测试驱动开发和探索性测试方法.

现在,我更容易找到我编写的代码的测试用例.但是,当我不是测试功能的开发人员时,我很高兴知道如何发现测试用例.比如说,让我们有一个基本的用户注册表单,我们在各种网站上看到.假设测试它的人不是表单的开发人员,那么应该如何测试表单上的输入字段,您的策略是什么?你会如何发现测试用例?我相信这种测试可以从探索性测试方法中获益,但我可能在这里错了.

我很感激你对此的看法.

谢谢,Byte

testing exploratory discovery testcase

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

应该使用TestCase或FunctionTestCase在python中进行测试吗?

在尝试在python中获得TDD的预感时,我遇到了这个FunctionTestCase类.我明白,它定义了TestCase类的等效函数.

assertEqual = failUnlessEqual(self, first, second, msg=None)
assertNotEqual = failIfEqual(self, first, second, msg=None)
# and so on...
Run Code Online (Sandbox Code Playgroud)

使用中是否存在显着差异,FunctionTestCase或者是味道问题?

python testcase python-unittest

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

如何在json文件中写入我的数据?

如何在json文件中写入我的数据?这是我的尝试:

from django.test import TestCase
from django_dynamic_fixture import G
import content.factories
from django.core import serializers
from content.models import UserProfile, Delivery
from django.contrib.auth.models import User

class DeliveryTest(TestCase):
    def test_sample_data(self):
        for i in range(0,10):
            user = content.factories.UserFactory.create()
            print user
            for j in range(0, 50):
                delivery = content.factories.DeliveryFactory.create(user=user)
                print delivery

                with open("file.json", "w") as out:
                    data = serializers.serialize("json", User.objects.all() ) 

                with open("file.json", "w") as out:
                    data2 = serializers.serialize("json", Delivery.objects.all() )
Run Code Online (Sandbox Code Playgroud)

输出(打印):http://dpaste.com/hold/923339/

python django unit-testing testcase

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

F#中的NUnit 3测试的测试用例

我正在尝试使用NUnit为F#项目设置测试套件。似乎特别是在测试诸如解析器和类型检查器之类的东西时,通常具有一列有效输入数据和一列无效数据。测试本身实际上是相同的,因此我正在寻找一种聪明的方法来避免为每个数据项编写测试函数,而是将测试函数与数据分开。显然,这似乎有一个所谓的测试用例,但是我很难找到有关将NUnit 3与F#一起使用的全面文档,尤其是针对我的场景最佳实践示例

非常感谢任何指针和提示!

f# testcase nunit-3.0

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

NUnit TestCase预期消息

所以我希望能够在其中指定不同的Exception消息,TestCase但不知道如何完成

这是原作

[Test]
[ExpectedException(typeof(SystemException), ExpectedMessage = "Holiday cannot start or end on a weekend or non-working day")]

public void AddHolidays_StartsInvlaid()
{}
Run Code Online (Sandbox Code Playgroud)

这是TestCase

[TestCase("27/04/2025", "28/05/2025", "FullDay", "FullDay", ExpectedMessage = "Holiday cannot start or end on a weekend or non-working day")]
[ExpectedException(typeof(SystemException), ExpectedMessage)]

public void AddHolidays_Exceptions(string dateFrom, string dateTo, string fromPeriod, string toPeriod)
{}
Run Code Online (Sandbox Code Playgroud)

该方法工作正常但我只是希望能够使用NUnit指定异常消息 TestCase

c# nunit unit-testing exception testcase

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

我可以获取机器人框架内测试用例步骤的统计信息吗?

为了优化执行时间,我创建了一些相互依赖的测试用例,我希望不仅为每个测试用例和测试用户获取度量和统计信息.但我也希望为每个步骤生成统计数据和指标.那可能吗 ?PS:我正在使用团队城市进行持续整合.

最好的祝福,

埃姆纳A.

teamcity test-suite testcase robotframework appium

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