标签: tdd

使用 c# 计算 Zip 文件中的文件数

我正在生成一些 .csv 文件,我需要将其压缩到一个 Zip 文件中。好的,我有一个框架可以做到这一点,可能一切都会好起来的。

但!正如 TDD 所说,在我进行一些测试后,我只能编写代码!

我的第一个测试听起来很简单,但是我在读取 Zip 文件时遇到了一些问题,有人知道一种计算 zip 文件中文件数量的简单方法吗?

c# tdd zip

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

Rspec to skip devise action in controller - sign_in_and_redirect

I have integrated rails application with omniauth and devise integration. In one the controller I have -

def create
     # some 
     # stuff 
     # here
   sign_in_and_redirect(:person, @person)
     # some 
     # stuff 
     # here
 end 
Run Code Online (Sandbox Code Playgroud)

as this action is from devise, i shouldn't be testing this action but only presence of it(correct me here if i am wrong.). Also, as I am mocking this person object, it doesn't have methods to pass origin sign_in_and_redirect action.

So, how can test this controller …

ruby tdd rspec ruby-on-rails devise

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

在 Behat Mink 场景中检查单选按钮状态?

我需要在输出中查看是否选中了给定的单选按钮。我应该使用什么样的定义?我在谷歌上搜索了很多,但没有找到解决方案(这可能就在我面前,因为有人可能会向我保证)。

tdd symfony gherkin behat mink

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

node.js Mocha:如何重用在本地设置 before() 钩子中定义的变量?

更新

在我的 ('resource' 测试中,我创建了一个新用户

/**
 * root level hooks
 */
before((done) => {
  const newUser = new User({
    username: 'johndoe',
    password: 'jdpwd',
    email: 'johndoe@example.com',
    mobileNumber: 123456789
  });
  newUser.save((err) => {
    // console.log('error: ', err);
    done();
  });
});
Run Code Online (Sandbox Code Playgroud)

我想在我的测试中重用用户 ID:

describe('## Resource APIs', () => {
const user = User.findOne({ username: 'johndoe' });
console.log('got user: ', user.id);
  let resource = {
    name: 'RS123',
    description: 'RS123Description',
    owner: user._id,   <= should be the id of the newUser
    private: true
  };
  describe('# POST /api/v1/resources', …
Run Code Online (Sandbox Code Playgroud)

tdd mocha.js node.js

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

反应如何测试在 FileReader onload 函数中调用的函数

我在一个组件中有以下代码。我想测试表单的 onSubmit,它在 reader 中调用 this.props.onUpload 方法。我该如何测试?我的期望测试不起作用,我猜这是因为 this.props.onUpload 在 reader.onload 函数中?

上传表单.js

handleSubmit(e) {
    e.preventDefault();

    var inputData = '';
    var file = this.state.file;
    if (file) {
        var reader = new FileReader();
        reader.onload = (function(file) {
            return function(e) {
                inputData = e.target.result;
                this.props.onUpload(inputData);
            };
        })(file).bind(this);
        reader.readAsText(file);            
    }

}

render() {
    return(
        <form onSubmit={this.handleSubmit}>
            <label> Enter File: <br/>
                <input type="file" id="fileinput" onChange={this.handleChange}/>    
            </label>
            <input type="submit" value="Submit" className="btn-upload" />
        </form>
    );
}
Run Code Online (Sandbox Code Playgroud)

上传表单.test.js

const mockOnUpload = jest.fn();
const file = new File([""], "filename");
const …
Run Code Online (Sandbox Code Playgroud)

javascript tdd reactjs jestjs enzyme

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

Cypress.io如何构建复杂的测试

我想把我的公司从黄瓜切换到柏树.原因是我们正在慢慢采用SPA方法,我们遇到很多问题,黄瓜(严重定制)不知道如何正确测试(不知道何时加载应用程序)我们花了很多时间只是为每个测试修复该问题.应用程序真的很大,现在我们用黄瓜写了数千个测试.

所以我们的用例在我们实际测试之前需要多个动作.示例路径

1)注册新用户(唯一用户需要有电子邮件,名字和姓氏)

2)创建新的报价(多步骤报价创建机制,上传图像等)

3)我们实际上可以开始做某事

因此,需要在每个文件之前执行此提供和用户创建(在某些情况下,我们需要超过1个用户和多于1个提供,具体取决于测试)

在黄瓜中,我们已经编写了所有这些机制.但是如何在柏树中构建这个呢?

我们应该创建单独的文件夹吗 我们可以称之为的行动?(这意味着我们将这些行为作为功能).

我不是e2e测试员(我是JS开发人员),但由于所有QA都已消失,因此我有责任维护和支持e2e测试.

tdd cucumber e2e-testing cypress

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

添加到私有列表以进行TDD单元测试

我正在学习TDD和模拟,我想知道如何将一些对象添加到私有列表中以测试方法和属性。我的代码的基本部分如下:

public class Account
{
    private List<Transaction> transactions = new List<Transaction>();

    public decimal Balance
    {
        get
        {
            throw new NotImplementedException();
            // Should be calculated by adding amounts of all transactions 
            // from private list
        }
    }

    public void AddTransaction(Transaction transaction)
    {
        throw new NotImplementedException();
    }
}

public class Transaction
{
    public decimal Amount { get; set; }
    public string Note { get; set; }
    public DateTime DateTime { get; set; }

    public Transaction(decimal amount, string note, DateTime dateTime)
    {
        Amount …
Run Code Online (Sandbox Code Playgroud)

c# tdd unit-testing mocking

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

测试接口还是类?

我是 Java 新手,对使用 JUnit 和 Mockito 测试代码感到困惑。

我在 github 上分叉了一个项目,其中的任务是编写 Junit 测试, AccountService它是一个接口。我不知道的是我必须测试什么?接口或实现接口的类?

这是AccountService

public interface AccountService {
    public Operation deposit(String accountNumber, int amount);
    public Operation withdraw(String accountNumber, int amount);
    public OperationsDto history(String accountNumber);
}
Run Code Online (Sandbox Code Playgroud)

这是AccountService实现

@Service
public class AccountServiceImpl implements  AccountService {

    @Autowired
    private AccountRepository accountRepository;
    @Autowired
    private OperationRepository operationRepository;

    @Autowired
    OperationConverter operationConverter;


    public Operation deposit(String accountNumber, int amount) {
        checkAmount (amount);

        AccountEntity account = getAccount (accountNumber);

        int balance =  account.getBalance();
        balance = balance …
Run Code Online (Sandbox Code Playgroud)

java tdd junit mockito

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

使用数据库H2在Spring Boot中进行测试

我正在尝试在具有H2数据库的Spring Boot api上运行测试中的测试,但是,当尝试运行测试时,系统使用的是主要资源中的application.properties而不是测试。我尝试将文件命名为application-test.properties,并@ActiveProfiles("test")在测试类中使用批注,但这不起作用(先将测试放入main / resource中,然后再放入test / resouce中)现在我不知道该尝试什么。

我的main / resource / apllication.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/chamados
spring.datasource.username=root
spring.datasource.password=12345
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
Run Code Online (Sandbox Code Playgroud)

我的测试/资源/ application.properties:

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=

spring.h2.console.enabled=false

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
Run Code Online (Sandbox Code Playgroud)

我刚刚运行的测试类:

@RunWith(SpringRunner.class)
@SpringBootTest
public class BackEndApplicationTests {

@Test
public void contextLoads() {
}

}
Run Code Online (Sandbox Code Playgroud)

我的pom.xml:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <jwt.version>0.9.1</jwt.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
        <dependency> …
Run Code Online (Sandbox Code Playgroud)

tdd h2 spring-boot

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

如果一个方法调用另一个方法,它是单元测试还是集成测试?

我是 tdd 概念的初学者,所以我的问题是,如果我有一个方法调用另一个方法,听起来很简单,它是单元测试还是集成测试?如果是集成测试,那只是因为我的方法调用了另一个方法并且方法之间存在“集成”?

testing tdd integration-testing unit-testing

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