

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Framework di test
<a name="test-framework-reporting"></a>

Gli argomenti di questa sezione mostrano come impostare la reportistica dei test per vari framework di test. AWS CodeBuild 

**Topics**
+ [Impostare i report dei test con Jasmine](test-report-jasmine.md)
+ [Impostare i report dei test con Jest](test-report-jest.md)
+ [Impostare i report dei test con pytest](test-report-pytest.md)
+ [Imposta la reportistica dei test con RSpec](test-report-rspec.md)

# Impostare i report dei test con Jasmine
<a name="test-report-jasmine"></a>

La procedura seguente mostra come configurare la reportistica dei test AWS CodeBuild con il framework di test [JasmineBDD](http://jasmine.github.io/). 

La procedura richiede i seguenti prerequisiti:
+ Hai un progetto esistente. CodeBuild 
+ Il tuo progetto è un progetto Node.js impostato per utilizzare il framework di test Jasmine.

Aggiungi il [https://www.npmjs.com/package/jasmine-reporters](https://www.npmjs.com/package/jasmine-reporters) pacchetto alla sezione `devDependencies` del file `package.json` del tuo progetto. Questo pacchetto contiene una raccolta di classi JavaScript reporter che possono essere utilizzate con Jasmine. 

```
npm install --save-dev jasmine-reporters
```

Se non è già presente, aggiungi lo script `test` al file `package.json` del tuo progetto. Lo `test` script assicura che Jasmine venga chiamato quando **npm test** viene eseguito.

```
{
  "scripts": {
    "test": "npx jasmine"
  }
}
```

CodeBuild supporta i seguenti reporter di test di Jasmine:

**JUnitXmlReporter**  
Utilizzato per generare report nel formato `JunitXml`.

**NUnitXmlReporter**  
Utilizzato per generare report nel formato `NunitXml`.

Un progetto Node.js con Jasmine avrà, per impostazione predefinita, una sottodirectory `spec`, che contiene gli script di configurazione e test Jasmine. 

Per configurare Jasmine e generare report nel formato `JunitXML`, creare un'istanza del reporter `JUnitXmlReporter` aggiungendo il seguente codice ai test. 

```
var reporters = require('jasmine-reporters');

var junitReporter = new reporters.JUnitXmlReporter({
  savePath: <test report directory>,
  filePrefix: <report filename>,
  consolidateAll: true
});

jasmine.getEnv().addReporter(junitReporter);
```

Per configurare Jasmine e generare report nel formato `NunitXML`, creare un'istanza del reporter `NUnitXmlReporter` aggiungendo il seguente codice ai test. 

```
var reporters = require('jasmine-reporters');

var nunitReporter = new reporters.NUnitXmlReporter({
  savePath: <test report directory>,
  filePrefix: <report filename>,
  consolidateAll: true
});

jasmine.getEnv().addReporter(nunitReporter)
```

I report dei test vengono esportati nel file specificato da/. *<test report directory>* *<report filename>*

Nel file `buildspec.yml`, aggiungere/aggiornare le sezioni seguenti.

```
version: 0.2

phases:
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - npm build
      - npm test

reports:
  jasmine_reports:
    files:
      - <report filename>
    file-format: JUNITXML
    base-directory: <test report directory>
```

Se si utilizza il formato del report `NunitXml`, modificare il valore `file-format` nel modo seguente.

```
    file-format: NUNITXML
```

# Impostare i report dei test con Jest
<a name="test-report-jest"></a>

La seguente procedura mostra come configurare la reportistica dei test AWS CodeBuild con il framework di test [Jest](https://jestjs.io/). 

La procedura richiede i seguenti prerequisiti:
+ Hai un progetto esistente CodeBuild .
+ Il progetto è un progetto Node.js impostato per utilizzare il framework di test Jest.

Aggiungi il [https://www.npmjs.com/package/jest-junit](https://www.npmjs.com/package/jest-junit)pacchetto alla `devDependencies` sezione del `package.json` file del tuo progetto. CodeBuild utilizza questo pacchetto per generare report nel `JunitXml` formato.

```
npm install --save-dev jest-junit
```

Se non è già presente, aggiungi lo script `test` al file `package.json` del tuo progetto. Lo `test` script assicura che Jest venga chiamato quando **npm test** viene eseguito.

```
{
  "scripts": {
    "test": "jest"
  }
}
```

Configurare Jest per utilizzare il reporter `JunitXml` aggiungendo quanto segue al file di configurazione Jest. Se il progetto non dispone di un file di configurazione Jest, creare un file denominato `jest.config.js` nella radice del progetto e aggiungere quanto segue. I report dei test vengono esportati nel file specificato da*<test report directory>*/. *<report filename>*

```
module.exports = {
  reporters: [
    'default',
    [ 'jest-junit', {
      outputDirectory: <test report directory>,
      outputName: <report filename>,
    } ]
  ]
};
```

Nel file `buildspec.yml`, aggiungere/aggiornare le sezioni seguenti.

```
version: 0.2

phases:
  pre_build:
    commands:
      - npm install
  build:
    commands:
      - npm build
      - npm test

reports:
  jest_reports:
    files:
      - <report filename>
    file-format: JUNITXML
    base-directory: <test report directory>
```

# Impostare i report dei test con pytest
<a name="test-report-pytest"></a>

La seguente procedura mostra come configurare la reportistica dei test AWS CodeBuild con il framework di [test pytest](https://docs.pytest.org/). 

La procedura richiede i seguenti prerequisiti:
+ Hai un progetto esistente CodeBuild .
+ Il tuo progetto è un progetto Python che è impostato per utilizzare il framework di test pytest.

Aggiungere la seguente voce alla fase `build` o `post_build` del file `buildspec.yml`. Questo codice rileva automaticamente i test nella directory corrente ed esporta i report dei test nel file specificato da*<test report directory>*/*<report filename>*. Il report utilizza il formato `JunitXml`.

```
      - python -m pytest --junitxml=<test report directory>/<report filename>
```

Nel file `buildspec.yml`, aggiungere/aggiornare le sezioni seguenti.

```
version: 0.2

phases:
  install:
    runtime-versions:
      python: 3.7
    commands:
      - pip3 install pytest
  build:
    commands:
      - python -m pytest --junitxml=<test report directory>/<report filename>

reports:
  pytest_reports:
    files:
      - <report filename>
    base-directory: <test report directory>
    file-format: JUNITXML
```

# Imposta la reportistica dei test con RSpec
<a name="test-report-rspec"></a>

La procedura seguente mostra come configurare i report sui test AWS CodeBuild con il [framework di RSpec test](https://rspec.info/). 

La procedura richiede i seguenti prerequisiti:
+ Hai un CodeBuild progetto esistente.
+ Il tuo progetto è un progetto Ruby configurato per utilizzare il framework di RSpec test.

Aggiungi/aggiorna quanto segue nel tuo file `buildspec.yml`. Questo codice esegue i test nella *<test source directory>* directory ed esporta i report dei test nel file specificato da*<test report directory>*/*<report filename>*. Il report utilizza il formato `JunitXml`.

```
version: 0.2

phases:
  install:
    runtime-versions:
      ruby: 2.6
  pre_build:
    commands:
      - gem install rspec
      - gem install rspec_junit_formatter
  build:
    commands:
      - rspec <test source directory>/* --format RspecJunitFormatter --out <test report directory>/<report filename>
reports:
    rspec_reports:
        files:
            - <report filename>
        base-directory: <test report directory>
        file-format: JUNITXML
```