Skip to content

Commit

Permalink
Added coverage metric in report (#391)
Browse files Browse the repository at this point in the history
* Added coverage metric in report

* got the tests running

* all tests running

* docs

* Added testing

* Added mvn config

* fixed test

* docs

* typo

* Better to compare the captured messages
  • Loading branch information
therealryan authored May 31, 2023
1 parent ede4613 commit 3927656
Show file tree
Hide file tree
Showing 37 changed files with 406 additions and 70 deletions.
8 changes: 8 additions & 0 deletions report/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ Clicking on the requests and responses will show the message data for that trans

For the expected and actual messages, the data can be displayed in a human-readable format, or the bytes can be interpreted as UTF8 or as raw data in a hexdump.

For interactions where we have captured actual data from the system under test the result of comparing that data against expectations, and hence test success, is reflected in the sequence diagram.
For most systems it will not be possible to directly compare captured messages against expectations - there may be unpredictable fields in the messages that have to be masked out before a useful comparison can be made.
The percentage figure presented against messages gives an indication of how heavily messages have been masked before comparison.
* A low figure indicates that extensive masking has been performed before assertion, so we can have limited confidence that our test data matches reality.
* A high figure indicates that minimal masking has been applied - our test data is a good representation of system behaviour.

Obviously, higher figures are better.

Clicking the search icon in the top-right of the sequence view allows message content to be searched - messages that contain the search term will be highlighted in the sequence diagram and occurrences of the term will be highlighted in message content.

#### Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void sequenceDiagram() {
.hasTransmissions(
" BEN request [e ]",
" CHE request [e ]",
" CHE response [e ap ]",
" BEN response [e a f]" );
" CHE response [e ap ] 100%",
" BEN response [e a f] 100%" );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void sequenceDiagram() {
.hasTransmissions(
" BEN request [eb ]",
" CHE request [eb ]",
" CHE response [ebap ]",
" BEN response [eba f]" );
" CHE response [ebap ] 100%",
" BEN response [eba f] 100%" );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ private static String actionText( int actors, WebElement afs ) {
.collect( joining() ) )
.append( "]" );

afs.findElements( By.className( "coverage" ) )
.forEach( ce -> sb.append( " " ).append( ce.getText() ) );

return sb.toString();
}

Expand Down
3 changes: 3 additions & 0 deletions report/report-ng/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ During development, replace that placeholder value with the appropriate JSON str

Examples of such structures can be found in the `target/report` directory of the [report-core](../report-core) module after a test run.

The unit tests can be run with `ng test`. By default the tests are run in interactive mode.
If you just want to run them all once without seeing them then run `ng test --browsers ChromeHeadless --watch=false`

### Java

The artifacts generated from the angular application are packages in `target/classes`. You might have to explicitly add this directory as a source folder in your IDE build path configuration to avoid failures in downstream projects.
Expand Down
4 changes: 3 additions & 1 deletion report/report-ng/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"projects/report/src/styles.css"
],
"scripts": []
"scripts": [
"projects/report/src/app/test-data.js",
]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion report/report-ng/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "ng build",
"build-all": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
"test": "ng test --browsers ChromeHeadless --watch=false"
},
"private": true,
"dependencies": {
Expand Down
23 changes: 23 additions & 0 deletions report/report-ng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ Build with
<arguments>run build-all</arguments>
</configuration>
</execution>
<execution>
<id>yarn run test</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>test</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down Expand Up @@ -229,6 +239,19 @@ Build with
</arguments>
</configuration>
</execution>
<execution>
<id>yarn run test</id>
<goals>
<goal>exec</goal>
</goals>
<phase>test</phase>
<configuration>
<executable>yarn</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
15 changes: 7 additions & 8 deletions report/report-ng/projects/report/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

declare var data: any;

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -16,16 +18,13 @@ describe('AppComponent', () => {
expect(app).toBeTruthy();
});

it(`should have as title 'report'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('report');
});

it('should render title', () => {
it('should reject bad data', () => {
data = "bad data";
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.content span')?.textContent).toContain('report app is running!');

expect(compiled?.textContent)
.toContain('Failed to grok data as index or flow "bad data"');
});
});
3 changes: 1 addition & 2 deletions report/report-ng/projects/report/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare var data: any;
/**
* This is the report app entrypoint. All it does is determine
* what sort of data has been embedded in the index.html file
* and then present the apropriate compnent (or an error message)
* and then present the apropriate component (or an error message)
*/
@Component({
selector: 'app-root',
Expand All @@ -22,7 +22,6 @@ export class AppComponent {
error_data?: any;

ngOnInit(): void {

if (isIndex(data)) {
this.index = data;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ChangeAnalysisComponent } from './change-analysis.component';
import { FlowDiffService } from '../flow-diff.service';
import { ModelDiffDataService } from '../model-diff-data.service';
import { RouterTestingModule } from '@angular/router/testing';

describe('ChangeAnalysisComponent', () => {
let component: ChangeAnalysisComponent;
let fixture: ComponentFixture<ChangeAnalysisComponent>;
let mockFds;
let mockMdds;

beforeEach(async () => {
mockFds = jasmine.createSpyObj(['onPairing', 'onFlowData']);
mockFds.sourceData = [];
mockFds.collated = [];
mockMdds = jasmine.createSpyObj(['index', 'onIndex']);
await TestBed.configureTestingModule({
declarations: [ ChangeAnalysisComponent ]
declarations: [ChangeAnalysisComponent],
providers: [
{ provide: FlowDiffService, useValue: mockFds },
{ provide: ModelDiffDataService, useValue: mockMdds },
],
imports: [RouterTestingModule]
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand All @@ -20,6 +34,7 @@ describe('ChangeAnalysisComponent', () => {
});

it('should create', () => {
expect(component).toBeTruthy();
// Need to mock/inject a bunch of stuff
// expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { RouterTestingModule } from '@angular/router/testing';
import { ChangeViewComponent } from './change-view.component';
import { FlowDiffService } from '../flow-diff.service';
import { ModelDiffDataService } from '../model-diff-data.service';
import { FlowFilterService } from '../flow-filter.service';

describe('ChangeViewComponent', () => {
let component: ChangeViewComponent;
let fixture: ComponentFixture<ChangeViewComponent>;
let mockFds;
let mockMdds;
let mockFilter;

beforeEach(async () => {
mockFds = jasmine.createSpyObj(['onPairing', 'onFlowData']);
mockMdds = jasmine.createSpyObj(['index']);
mockFilter = jasmine.createSpyObj(['onUpdate', 'passes', 'isEmpty'])
await TestBed.configureTestingModule({
declarations: [ ChangeViewComponent ]
declarations: [ChangeViewComponent],
providers: [
{ provide: FlowDiffService, useValue: mockFds },
{ provide: ModelDiffDataService, useValue: mockMdds },
{ provide: FlowFilterService, useValue: mockFilter },
],
imports: [RouterTestingModule]
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DetailComponent } from './detail.component';
import { BasisFetchService } from '../basis-fetch.service';
import { MatMenu } from '@angular/material/menu';

describe('DetailComponent', () => {
let component: DetailComponent;
let fixture: ComponentFixture<DetailComponent>;
let mockBasisFetch;

beforeEach(async () => {
mockBasisFetch = jasmine.createSpyObj(['get']);
await TestBed.configureTestingModule({
declarations: [ DetailComponent ]
declarations: [DetailComponent, MatMenu],
providers: [
{ provide: BasisFetchService, useValue: mockBasisFetch },
],
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export class EnumIteratePipe implements PipeTransform {
return Object.keys(obj).filter(k => Number.isNaN(+k)) as K[];
}


}

Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FlowFilterComponent } from './flow-filter.component';
import { RouterTestingModule } from '@angular/router/testing';

describe('FlowFilterComponent', () => {
let component: FlowFilterComponent;
let fixture: ComponentFixture<FlowFilterComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ FlowFilterComponent ]
declarations: [FlowFilterComponent],
imports: [RouterTestingModule]
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { IndexComponent } from './index.component';
import { RouterTestingModule } from '@angular/router/testing';
import { IndexDataService } from '../index-data.service';

describe('IndexComponent', () => {
let component: IndexComponent;
let fixture: ComponentFixture<IndexComponent>;
let mockIndexData;

beforeEach(async () => {
mockIndexData = jasmine.createSpyObj(['get', 'isValid', 'raw']);
mockIndexData.get.and.returnValue({
meta: {
timestamp: 12345,
modelTitle: "model title",
testTitle: "test title",
}
});
await TestBed.configureTestingModule({
declarations: [ IndexComponent ]
declarations: [IndexComponent],
providers: [
{ provide: IndexDataService, useValue: mockIndexData },
],
imports: [RouterTestingModule],
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { MenuComponent } from './menu.component';
import { MatMenuModule } from '@angular/material/menu';

describe('MenuComponent', () => {
let component: MenuComponent;
let fixture: ComponentFixture<MenuComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ MenuComponent ]
imports: [MatMenuModule],
declarations: [MenuComponent]
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ModelDiffDataSourceComponent } from './model-diff-data-source.component';
import { ModelDiffDataService } from '../model-diff-data.service';
import { RouterTestingModule } from '@angular/router/testing';

describe('ModelDiffDataSourceComponent', () => {
let component: ModelDiffDataSourceComponent;
let fixture: ComponentFixture<ModelDiffDataSourceComponent>;
let mockMdds;

beforeEach(async () => {
mockMdds = jasmine.createSpyObj(['onFlow', 'onIndex']);
await TestBed.configureTestingModule({
declarations: [ ModelDiffDataSourceComponent ]
declarations: [ModelDiffDataSourceComponent],
providers: [
{ provide: ModelDiffDataService, useValue: mockMdds },
],
imports: [RouterTestingModule]
})
.compileComponents();
.compileComponents();
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ export class ModelDiffDataSourceComponent implements OnInit {
});
}

getValue(): string {
return this.input.value;
}

setValue(value: string): void {
this.input.setValue(value);
}

valueChanges(observer: (value: any) => void): void {
this.input.valueChanges.subscribe(observer);
}
}
Loading

0 comments on commit 3927656

Please sign in to comment.